php - 向导形式的拖曳按钮不同的调用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" ; }
?>
解决方案
我从一个朋友那里得到了一些帮助..他只是改变了这个:
var form_data = $(this).closest('form').serialize();
对此:
var form_data = new FormData($(this).closest('#form1').get(0));
他解决了我的问题。老实说,我不明白问题出在哪里,但他告诉我我发送了不同类型的数据>>谢谢每个人。:)
推荐阅读
- android - 尝试正确提取值但遇到问题
- django - 在 Django Admin 中删除模型历史记录还原按钮
- bash - 当不使用参数时,使用 ipython 为 python 命令别名的 Bash 函数
- average - 如何使用附近点的平均值添加更多点 - QGIS
- r - 如何将矢量切割成由它们的中心表示的 bin
- reactjs - 使用打字稿时动态导入的css文件不会被延迟
- amazon-web-services - 使用 Terraform 部署 AWS EKS Fargate
- java - Java单元测试中Windows上的测试资源路径
- c - 从C中的二进制文件中删除最后一个结构
- node.js - Appium-node.js - 我正在使用这个触摸功能并想点击这个特定的坐标。但它给了我一个错误