本篇教程介绍了jQuery教程 ajax请求后台数据成功后既不执行success也不执行error如何解决,希望阅读本篇文章以后大家有所收获,帮助大家对jQuery的理解更加深入。
<
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;
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标WEB前端jQuery频道!