Home >Web Front-end >JS Tutorial >What should I do if there is no reflection after successful ajax request for background data?
This time I will bring you how to deal with the problem of no reflection after the ajax request for background data is successful. What are the things to note ? The following is a practical case. Let’s take a look. . After the ajax request for background data in
jquery succeeds, neither success nor error is executed. In addition, the system reports an error: Uncaught SyntaxError: Unexpected identifier at Object.success, but The background can return data. The original code is as follows:
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;The main reason is that the data returned by the background is not in json format, and dataType: "json" is specified in the code. The solution is to change json to text. After modification The code is as follows:
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;
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Recommended reading:
Using jQuery EasyUI folding panel
Using tabs in jQuery EasyUI tab panel
jQuery adds new elements to dynamic list
The above is the detailed content of What should I do if there is no reflection after successful ajax request for background data?. For more information, please follow other related articles on the PHP Chinese website!