使用Ajax和jQuery邮政形式 [英] Post form with Ajax and jQuery
问题描述
开始学习阿贾克斯队(和jQuery),我遇到问题后表单数据,这是我解决不了自己。
Start learning Ajax (and jQuery), I encounter the issue with post form data, which I could not resolve myself.
首先,这里是一个简单的例子,我收集资料,张贴,并在新页面上显示的是:
First, here is the simple example where I collect data, post it, and displayed it on a new page:
<!-- index.html -->
<form id="myForm" action="test.php" method="post">
<input type="checkbox" id="ch1" name="Ch1" value="1">Check Box 1 <br />
<input type="checkbox" id="ch2" name="Ch2" value="2">Check Box 2 <br />
<input type="submit" id="myButton" />
</form>
<?php
// test.php
print_r($_POST);
?>
然后我尝试使用Ajax和jQuery。我稍微修改上面粘贴的形式:
Then I tried with Ajax and jQuery. I slightly modified the form pasted above:
<!-- index.html -->
<form id="myForm">
<input type="checkbox" id="ch1" name="Ch1" value="1">Check Box 1 <br />
<input type="checkbox" id="ch2" name="Ch2" value="2">Check Box 2 <br />
<input type="button" id="myButton" value="Submit"/>
</form>
这里是jQuery的功能:
And here is the jQuery function:
// script.js
$(document).ready(function () {
$("#myButton").click(function () {
$.ajax({
cache: false,
type: 'POST',
url: 'test.php',
data: $("#myForm").serialize()
});
});
});
我的问题是,如何重新实现jQuery函数呼应的结果在的test.php
标签?我爬了很多资源,但我没有找到任何解决方案。
My question is, how to reimplement the jQuery function to echo the result in the test.php
tab? I crawled the many resources, but i didn't find any solution.
在此先感谢任何指针。
最好的,安德烈
推荐答案
我相信你正在寻找的阿贾克斯<在
成功
/ code>选项参数。
I believe you're looking for the success
in the .ajax
options parameter.
$.ajax({
...
success: function(d){
alert(d);
}
});
这篇关于使用Ajax和jQuery邮政形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!