我正在为php页面制作ajax帖子。在php页面上,我回显结果,因此成功回调将记录它,但它不起作用。
JS:
$(function(){
$.ajax({
url : "http://XXXXXXX/bn/sample.php",
type : 'POST',
number: "1234567",
success : function (result) {
console.log("success");
console.log(result);
},
error : function () {
alert("error");
}
});
PHP:
<?php
$data = $_POST['number'];
echo json_encode($data);
?>
答案 0 :(得分:5)
那是因为您将number
设置为AJAX json对象中的属性。正确的属性是data
:
$.ajax({
url : "http://XXXXXXX/bn/sample.php",
type : 'POST',
data: {number: "1234567"},
success : function (result) {
console.log("success");
console.log(result);
},
error : function () {
alert("error");
}
});