【发布时间】:2014-07-25 07:07:17
【问题描述】:
您好,我正在使用 jquery - servlet 进行 parseerror ajax 调用。我迷路了。哦,请问该怎么办。
来自 servlet 的数据是有效的 json {"success":true,"SelectPartid":{"partidAll":"DA04321;"}}
如果我放弃dataType: 'json',this 工作正常。但是我不能使用这个代码
if (data.success) {
alert("SUCCESS!!");
//alert("success" + data.SelectPartid.partidAll);
}
所以,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);
}
}
});
});
【问题讨论】:
-
快速观察。
"DA04321;"是;肯定在双引号内吗? -
您确定响应看起来像您向我们展示的 JSON 吗?
-
我已经在jsonformatter.curiousconcept.com 进行了测试。这是一个有效的 json
-
@RGraham 是的,它在双引号内
-
@RGraham 那;当有多个结果时用作分隔符。
标签: javascript jquery ajax json servlets