首页 > 解决方案 > 向导形式的拖曳按钮不同的调用ajax

问题描述

我为这个问题的简单性向你道歉。但是我查看了您美丽的网站以找到我的问题的答案,但我并不幸运。我正在尝试建立自己的学生注册表格向导,作为大学研究生项目的简单步骤。我使用 PHP、JQuery 和 AJAX 来发送数据。

我的问题:

我有一个表单和按钮,前三个输入通过提交按钮在数据库中搜索并且效果很好,然后自动表单向导移动到下一个字段集,然后向学生显示输入字段以输入他的信息.

最后是通过 AJAX 将数据保存到数据库的按钮,这个按钮是我的问题。php 说未定义的索引。

这是 html 向导表单的代码

$('form').on('submit', function(e) {
  var $formInput = $(this).find('.fi');

  $formInput.each(function(i) {
    if (!$(this).val()) {
      e.preventDefault();
      $(this).addClass('input-error');
      return false;
    } else {
      if ($formInput.length === i + 1) {
        var id_high_school = $('[name="id_high_school"]').val();
        var SEC_SCHOOL_YEAR = $('[name="SEC_SCHOOL_YEAR"]').val().toString();
        var sum_high_school = $('[name="sum_high_school"]').val();

        alert(SEC_SCHOOL_YEAR);
        $.ajax({
          url: "select_for_modal_serch.php",
          method: "post",
          data: {
            id_high_school: id_high_school,
            SEC_SCHOOL_YEAR: SEC_SCHOOL_YEAR,
            sum_high_school: sum_high_school

          }
        }).done(function(datas) {
          $('#studint_detail').html(datas);
          $('#dataModal').modal("show");
        }).fail(function() {
          alert('fail..');
        });

      }


    }

  });


  return false;

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<form name="mainForm" action=" <?php echo $_SERVER['PHP_SELF'] . '#form1' ?> " id="form1" method="POST" enctype="multipart/form-data">

  <!-- condetion for regster -->
  <fieldset>
    <iframe src="license.html"></iframe>
  <input class="form-check-input" id="check_qury" type="checkbox" value="yes">  
    <div class="wizard-buttons">

      <button type="button" class="btn btn-next">التالي</button>

    </div>
  </fieldset>
  <fieldset>
    <!-- 3 <input type = text > to search for data from mysql -->
    <!--her is the submit button and is get data by ajax  -->
    <input type="submit" class="form-control btn btn-primary view-data" id="submit_high_school" value="بحث" name="submit_high_school" />
    <!-- by ajax is work and then is go to the next filedset -->
  </fieldset>
  <fieldset>
    <!-- mor data <input type = text > to search for data from mysql -->
    <button type="button" id="sava_data_to_tables" name="sava_data_to_tables" class="btn btn-next">
 <!-- this is the button of my problem cant send this form data to mysql -->
  </fieldset>
我执行此代码来解决问题,但没有任何效果:

$('#sava_data_to_tables').on('click', function (event) {

        var form_data = $(this).parents('form').serialize();

        var colage = $('[name="colage"]').val();
        var spichelest = $('[name="spichelest"]').val();
        
        // and rest of input type 

        $.ajax({
            url: "insert_into_info_contact.php",
            method: "POST",
            data: form_data,
            success: function (data) {
                alert(data);
            }, cache: false,
            contentType: false,
            processData: false
        });

    });

和我的 PHP :

 <?php 

// isset($_POST['sava_data_to_tables'])
//$_SERVER['REQUEST_METHOD']==='POST'
// !empty($_POST)

if ($_SERVER['REQUEST_METHOD']==='post')
{  echo "you submit data" 
;}
else {

echo "its not work" ; }
?> 

标签: phpjqueryajax

解决方案


我从一个朋友那里得到了一些帮助..他只是改变了这个:

var form_data = $(this).closest('form').serialize();

对此:

 var form_data = new FormData($(this).closest('#form1').get(0));

他解决了我的问题。老实说,我不明白问题出在哪里,但他告诉我我发送了不同类型的数据>>谢谢每个人。:)


推荐阅读