Php jQuery提交函数不支持';不发送输入提交
我在为我的问题寻找答案,但我没有找到答案。这里有一个类似的主题,但我有不同的代码,我不知道如何将这个主题的答案与我的代码相匹配 这是我的问题。我正在将id为Php jQuery提交函数不支持';不发送输入提交,php,jquery,ajax,Php,Jquery,Ajax,我在为我的问题寻找答案,但我没有找到答案。这里有一个类似的主题,但我有不同的代码,我不知道如何将这个主题的答案与我的代码相匹配 这是我的问题。我正在将id为order\u form的表单发送到test.php。 除了输入提交之外,所有表单值都正确发送。我的脚本基于检查是否已发送 下面是我用来发送表单的代码 $("#order_form").submit(function() { $.ajax({ type: "POST", url: "inc
order\u form
的表单发送到test.php
。
除了输入提交
之外,所有表单值都正确发送。我的脚本基于检查
是否已发送
下面是我用来发送表单的代码
$("#order_form").submit(function() {
$.ajax({
type: "POST",
url: "includes/test.php",
data: $("#order_form").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data);
}
});
return false; // avoid to execute the actual submit of the form.
});
下面是test.php的内容
echo '<pre>';
print_r($_POST);
echo '</pre>';
echo';
打印(邮政美元);
回声';
这是我的表格,因为我的表格非常大
<form>
<input type="text" name="foo" value="bar">
<input type="submit" name="submitTest" value="Hello World!">
</form>
在HTML5表单中,当您向ajax函数传递参数和变量时,“提交输入”中的值数据不会被传递。因此,如果您将表单设置为:
<form>
<input type="text" name="foo" value="bar">
<input type="hidden" name="sendform" value="ZAMAWIAM">
<input type="submit" name="submitTest" value="Hello World!">
</form>
“submitTest”的值未通过发送。唯一被发送的是参数“foo”,其值为“bar”。在这种情况下,“submitTest”只提交表单并执行ajax调用
要解决这个问题,只需在表单中添加一个隐藏元素。
现在看起来是这样
$(function(){
//code here
});
这将把值发送给ajax调用,您可以将其用于任何可能需要的用途 确保将jquery代码包装在
$(function(){
$("#order_form").submit(function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "includes/test.php",
data: $("#order_form").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data);
}
});//end ajax
});//end on submit
});//end jquery
同样不要忘记防止默认事件,下面是jquery代码的重写
用html实现的订单表单会很有帮助。
避免执行表单的实际提交。
为此使用e.stopPropagation()
。因此无法发送该表单,我必须重写代码。这正是我所做的。你的建议很有帮助。非常感谢。
$(function(){
$("#order_form").submit(function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "includes/test.php",
data: $("#order_form").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data);
}
});//end ajax
});//end on submit
});//end jquery