Jquery ajax json解析错误有效的json数据
jquery ajax json parseerror valid json data
我正在使用jquery - servlet进行ajax调用。我迷路了。哦,请做些什么。并且来自servlet的数据是有效的json {"success":true,"SelectPartid":{"partidAll":"DA04321;"}}
如果我丢弃dataType: 'json',
,这个工作很好。但是我不能使用这个代码
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);
}
}
});
});
application/json
这个解决方案它不能相信我浪费了2个小时,因为这一行。ajax不会导致错误,它在servlet中。
这一行
response.setContentType("text/html;charset=UTF-8");
我只是把它改成
response.setContentType("application/json;charset=UTF-8");
,然后错误就消失了。感谢上帝
-复制我的上一条评论,我相信这会对某些人有用。
相关文章:
- 如何将数组转换为有效的json
- 当其他解析器认为意外的令牌有效时,json.parse会失败
- jquery ajax”;SyntaxError:意外的输入结束“;基于有效的JSON
- 使用Underscore.js修改json数组中所选元素的更有效方法
- 将JSON存储和恢复到此Ionic应用程序的最有效方法
- JSON.parse给了我一个错误,但JSONLint说它'是一个有效的json
- I'我在页面加载时将整个$_SESSION变量放入一个json对象中.虽然这对我有效,但这是一个好的做法吗
- $http-get方法即使使用AngularJS中.Net WebApi的有效json也会失败
- 从文件目录结构创建JSON数据的有效功能
- jQuery.parseJSON()未在Windows服务器上解码有效的Json字符串
- 正在将字符串转换为有效的JSON对象
- 接收package.json的解析错误.验证为有效的json
- 接收json异步响应的最有效方式
- JavaScript JSON.任何更有效的方法
- 修复无效JSON的最有效方法
- d3.json有效,但$.getJson失败
- 具有JSON有效负载的Crossrider ajax帖子请求在Rails后端中无法正确接收
- Json响应无效,Json有效
- 如何使我的json有效
- JSON有效负载问题,javascript编码