【发布时间】:2015-03-17 16:22:20
【问题描述】:
这是我第一次写ajax 下面是我的结构
提交的.php
<?php $a = $_POST['a']; // an input submitted from index.php ?>
<button>bind to jquery ajax</button> // call ajax
<span></span> // return ajax result here
<script>
$('button').on('click', function() {
event.preventDefault();
$.ajax({
method: "POST",
url: "test.php",
data: { "key" : 'data'}
})
.done(function( msg ) {
$('span').html(msg);
});
});
</script>
test.php
<?php echo $a; // will this work? ?>
ajax 返回空白...没有错误,我的 error_reporting 已开启。
【问题讨论】:
-
我注意到的第一件事是你应该有
$_POST['a']而不是$POST_['a']。 -
typo...我有大约 10 个输入需要传递给 ajax...有没有办法做到这一点?比如
echo $aindata:?