前端:
提交
var json = {
"classid": 1,
"zlclass": "测试"
};
$("#btn").click(function() {
$.ajax({
type: "POST",
url:"form.php",
contentType:"application/json;charset=utf-8",
data: JSON.stringify(json),
error: function(request) {
alert("Connection error");
},
success: function(data) {
$("#container").html(data);
}
});
});
后端:
header("Content-type:text/html;charset=UTF-8");
$data=json_decode($_POST['data']);
echo($data);
?>
结果test.html没有看到返回值,报错。对于php后台接收json数据处于刚入门阶段,求指点