[英]jquery ajax json parseerror valid json data
Hi im having parseerror ajax call using jquery - servlet. 您好,我使用jquery-servlet进行了parseerror ajax调用。 im at lost.
即时通讯迷路了。 oh please what to do.
哦,该怎么办。 and data from servlet is a valid json
{"success":true,"SelectPartid":{"partidAll":"DA04321;"}}
并且来自servlet的数据是有效的json
{"success":true,"SelectPartid":{"partidAll":"DA04321;"}}
if i discard the dataType: 'json',
this work fine. 如果我放弃
dataType: 'json',
这工作正常。 but then i cant use this code 但后来我不能使用此代码
if (data.success) { alert("SUCCESS!!"); //alert("success" + data.SelectPartid.partidAll); }
so, the ajax,please advise 所以,ajax,请告知
$("#select1").change(function() {
dataString = "Optionselected=" + $("#select1 option:selected").text();
alert("dataString : " + dataString);
$.ajax({
type: 'POST',
url: 'SelectAjx',
data: dataString,
dataType: 'json',
contentType: "application/json; charset=utf-8",
context: this,
success: function(data, textStatus, jqXHR) {
if (data.success) {
alert("SUCCESS!!");
//alert("success" + data.SelectPartid.partidAll);
}
},
error: function(jqXHR, exception) {
//alert('[jqXHR:' + jqXHR + '], [textStatus:' + textStatus + '], [thrownError:' + errorThrown + '])');
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
application/json
this solve it cant believe i waste 2 hours because of this line. application/json
此解决方案无法相信我会因为此行而浪费2个小时。 the ajax doesnt cause the error..its in the servlet. ajax不会在servlet中导致错误。
this is the line 这是线
response.setContentType("text/html;charset=UTF-8");
what i just dd is change it to 我只是dd将其更改为
response.setContentType("application/json;charset=UTF-8");
and there the error swooshd away.thank god 然后错误就消失了。感谢上帝
-copy from my last comment, im sure this gonna be useful to someone. -从我的最后评论复制,我确定这对某人有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.