jQuery的AJAX - 意外标记+ parsererror [英] jQuery AJAX - Unexpected token + parsererror
本文介绍了jQuery的AJAX - 意外标记+ parsererror的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了使用jQuery和AJAX今天的脚本,我也得到了一些错误......
I wrote a script using jQuery and AJAX today, and I get some errors...
脚本:
function changeAdmin(id) {
$(document).ready(function() {
$('#ta-modarea-'+id).fadeOut('fast');
$('#ta-m-loading-'+id).fadeIn('fast');
$.ajax({
type: 'POST',
url: 'ajax_utf.php?a=changeteamadmin',
dataType: 'json',
data: {
admin : $('#admin-id-'+id).val()
},
success: function(data) {
$('#ta-m-loading-'+id).fadeOut('fast');
$('#ta-modarea-'+id).text(data.msg).fadeIn('fast');
},
error: function(jqXHR, textStatus, errorThrown) {
$('#ta-m-loading-'+id).fadeOut('fast');
$('#ta-modarea-'+id).text('HTTP Error: '+errorThrown+' | Error Message: '+textStatus).fadeIn('fast');
}
});
return false;
});
}
运行结束后,我收到此错误信息: HTTP错误:语法错误:意外标记< |错误信息:parsererror
您能帮助我,我该怎么办?
Could you help me, what should I do?
推荐答案
您需要通过PHP发送应用程序/ JSON
头,像这样的:
You need to send an application/json
header via PHP , like this:
header('Content-type: application/json');
这是因为jQuery的发送和接收报头(应用程序/ JSON,文字/ JavaScript的
),这是 parseerror $ C的原因$ C>按
jqXHR
。
That's because jQuery sends an Accept header (application/json, text/javascript
), and this is the cause of parseerror
triggered by jqXHR
.
这篇关于jQuery的AJAX - 意外标记+ parsererror的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文