Home > Web Front-end > JS Tutorial > What should I do if there is no reflection after successful ajax request for background data?

What should I do if there is no reflection after successful ajax request for background data?

php中世界最好的语言
Release: 2018-03-15 14:28:28
Original
2970 people have browsed it

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;  
Copy after login
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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template