我已经在javascript中得到ajax响应但现在我想提交表单并希望ajax respone也在我的POST数组中

时间:2016-10-25 09:22:08

标签: javascript php jquery ajax forms

我想在数据库中添加数据,因为我希望ajax responce数组也在POST数组中但是没有这样做

<div class="form-group">
  <label for="focusedinput" class="col-sm-2 control-label">Campus Accreditation</label>
  <div class="col-sm-7">
    <?php Web_Interface::load_accreditation($obj_admin->adminCountry); ?>
    <script>
      jQuery("input[id=accreditation]").click(function() {
        var selectedCheckBoxArray = new Array();
        var n = jQuery("input[id=accreditation]:checked").length;
        if (n > 0) {
          jQuery("input[id=accreditation]:checked").each(function() {
            selectedCheckBoxArray.push($(this).val());
          });
          //send check box data value array to server using Ajax
          var data = {
            myCheckboxes: selectedCheckBoxArray
          };
          jQuery.ajax({
            url: "../process/ProcessAjaxChecking.php",
            data: data,
            type: "POST",
            success: function(data) {
              $('#getAcademics').html(data);
              $json = json_encode(data);
              $.ajax({
                url: "Example.php",
                type: "POST",
                dataType: "json",
                success: function(msg) {
                  $('#getAcademics').html(data);
                }
              });
            }
          });

        }
      });
    </script>
  </div>

提交表单之前 enter image description here

提交后 enter image description here

1 个答案:

答案 0 :(得分:0)

在你的value.php中,你给出了名字&#39; academicsCheckBoxes and you have paased in ajax myCheckboxes`。

更改

var data = {
    academicsCheckBoxes: selectedCheckBoxArray 
};

更新代码

<div class="form-group">
  <label for="focusedinput" class="col-sm-2 control-label">Campus Accreditation</label>
  <div class="col-sm-7">
    <?php Web_Interface::load_accreditation($obj_admin->adminCountry); ?>
    <script>
      jQuery("input[id=accreditation]").click(function() {
        var selectedCheckBoxArray = new Array();
        var n = jQuery("input[id=accreditation]:checked").length;
        if (n > 0) {
          jQuery("input[id=accreditation]:checked").each(function() {
            selectedCheckBoxArray.push($(this).val());
          });
          //send check box data value array to server using Ajax
          var data = {
            academicsCheckBoxes: selectedCheckBoxArray 
          };
          jQuery.ajax({
            url: "../process/ProcessAjaxChecking.php",
            data: data,
            type: "POST",
            success: function(data) {
              $('#getAcademics').html(data);
              $json = json_encode(data);
              $.ajax({
                url: "Example.php",
                type: "POST",
                dataType: "json",
                success: function(msg) {
                  $('#getAcademics').html(data);
                }
              });
            }
          });

        }
      });
    </script>
  </div>