我有一个具有以下行的 php 脚本:
echo json_encode(array('success'=>'true','userid'=>$userid, 'data' => $array));
它返回以下内容:
{
"success": "true",
"userid": "1",
"data": [
{
"id": "1",
"name": "Trigger",
"image": "",
"subtitle": "",
"description": "",
"range1": null,
"range2": null,
"range3": null
},
{
"id": "2",
"name": "DWS",
"image": "",
"subtitle": "",
"description": "",
"range1": null,
"range2": null,
"range3": null
}
]
}
但是当我如下调用 jQuery ajax 时:
$.ajax({
type: 'POST',
url: 'url',
crossDomain: true,
data: {name: name},
success: function(success, userid, data) {
if (success = true) {
document.write(userid);
document.write(success);
}
}
});
这userid
就是“成功”。实际success
的工作,它的true
.
是否返回了格式错误的数据?还是只是我的代码?
在此先感谢,尼尔