【发布时间】:2011-05-31 04:37:33
【问题描述】:
开始学习 Ajax(和 jQuery),我遇到了 post 表单数据的问题,我自己无法解决。
首先,这是我收集数据、发布数据并将其显示在新页面上的简单示例:
<!-- 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。我稍微修改了上面粘贴的表格:
<!-- 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 函数:
// script.js
$(document).ready(function () {
$("#myButton").click(function () {
$.ajax({
cache: false,
type: 'POST',
url: 'test.php',
data: $("#myForm").serialize()
});
});
});
我的问题是,如何重新实现 jQuery 函数以在 test.php 选项卡中回显结果?我爬了很多资源,但我没有找到任何解决方案。
提前感谢您的任何指点。
最好的,安德烈
【问题讨论】:
-
什么“标签”? test.php 是你的目标脚本。
标签: php jquery ajax forms post