这次给大家带来ajax请求后台数据成功后无反映应该如何处理,ajax请求后台数据成功后无反映的注意事项有哪些,下面就是实战案例,一起来看一下。
jquery中ajax请求后台数据成功后既不执行success也不执行error,此外系统报错:Uncaught SyntaxError: Unexpected identifier at Object.success,但后台能够返回数据,原代码如下:var source=[];
$.ajax({
type: "post",
url: "connectdb/select.jsp",
data: {database: "scmdb", selectsql: sql},
async: false, method: 'post',
dataType: "json",
success: function(data) {
eval("source="+data+";");
//source=eval(data);
alert("正确");
},
error: function(err) {
alert("错误");
}
});
return source;
主要原因在于后台返回的数据并非json格式,而在代码中指定了 dataType: "json", 解决方法是将 json改为text,修改后的代码如下:var source=[];
$.ajax({
type: "post",
url: "connectdb/select.jsp",
data: {database: "scmdb", selectsql: sql},
async: false, method: 'post',
dataType: "text",
success: function(data) {
eval("source="+data+";");
//source=eval(data);
alert("正确");
},
error: function(err) {
alert("错误");
}
});
return source;
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读: