我有这个代码:
$.ajax({
url: 'urlsubmit.php',
data: json_data,
dataType: 'json',
type: 'POST',
success: function(data) {
$('#saveResult_'+tnTopic_id).html("OK");
if(data.indexOf("ok") !== -1) {
$("#saveResult_"+tnTopic_id).html("Ok, am salvat!");
}
else {
$("#saveResult_"+tnTopic_id ).html(data);
//alert("A aparut o eroare:\n\r"+data);
}
},
error: function (jqXHR, textStatus, errorThrown) {
$('#saveResult_'+tnTopic_id).html(textStatus + ' | ' + errorThrown + ' | ' + jqXHR.responseText);
//alert(xhr.status);
//alert(thrownError);
}
});
}
在 urlsubmit.php 中我只回显“ok”
我得到了这个错误parsererror |语法错误:意外的标记 o
最佳答案
删除此 - (如果您没有使用 json 响应)
dataType: 'json',
jQuery 正在尝试将 ok
解析为 json,这就是您收到该错误的原因
关于php - jquery ajax使用echo时json请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17222721/