Php AJAX";parsererror"&引用;没有从文本到应用程序/json的转换;
我尝试使用简单的AJAX客户端和php作为restful服务器发布JSON。但是我正在解析这个json,它显示了错误 错误:“parsererror”,“没有从文本到应用程序/json的转换” 我的客户代码是Php AJAX";parsererror"&引用;没有从文本到应用程序/json的转换;,php,jquery,json,ajax,Php,Jquery,Json,Ajax,我尝试使用简单的AJAX客户端和php作为restful服务器发布JSON。但是我正在解析这个json,它显示了错误 错误:“parsererror”,“没有从文本到应用程序/json的转换” 我的客户代码是 <html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="http://ajax.googlea
<html>
<head>
<title>The jQuery Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#driver").click(function(event){
var person = {
name: 'df',
};
$.ajax({
url: './ajax.php',
dataType: "application/json",
//contentType: "json",
type:'post',
data: person,//{'FirstName':FirstName,'LastName':LastName},
success: function(msg) {
alert(msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
});
});
</script>
</head>
<body>
<div id="stage" style="background-color:cc0;">
STAGE
</div>
<input type="button" id="driver" value="Load Data" />
</body>
</html>
jQuery示例
$(文档).ready(函数(){
$(“#驱动程序”)。单击(函数(事件){
个人变量={
名称:‘df’,
};
$.ajax({
url:“./ajax.php”,
数据类型:“应用程序/json”,
//contentType:“json”,
类型:'post',
数据:person,//{'FirstName':FirstName,'LastName':LastName},
成功:功能(msg){
警报(msg);
},
错误:函数(XMLHttpRequest、textStatus、errorshown){
警报(文本状态);
}
});
});
});
阶段
我的服务器代码是
<?php
if ($_SERVER['REQUEST_METHOD'] == "GET") {
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
header('Content-type: application/json');
$jsonData = file_get_contents('php://input');
echo $jsonData;
//echo "true";
}
?>
Put
exit
在逻辑末尾,尝试以下操作:
<?php
if ($_SERVER['REQUEST_METHOD'] == "GET") {
...
} else if ($_SERVER['REQUEST_METHOD'] == "POST") {
header('Content-type: application/json');
$jsonData = file_get_contents('php://input');
echo $jsonData;
//echo "true";
exit;
}
?>
这个出口到底做什么?