The ultimate way to solve the parsererror error of ajax (the problem of json data transmitted from the background to the front end)The reason for this problem is that there is a problem with the data transmitted from the background to the front end. Ajax is particularly strict about the format of JSON. The following is the ajax request that will cause this problem $.ajax({ type:'get', url:"{php echo $this->createWebUrl('ajax',array('ac'=>'cunByXiangId'))}", data:{id:id}, dataType:'json', //This is the key to the problem success:function(obj){ },error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }); The main problem lies in the line of code dataType:'json', which means that the received data is in json format. At this time, we only need to delete this code and we will receive the string format. The data is then converted into json format. The following is the code $.ajax({ type:'get', url:"{php echo $this->createWebUrl('ajax',array('ac'=>'cunByXiangId'))}", data:{id:id}, success:function(obj){ obj=eval('('+obj+')');//This code converts the string into json format},error: function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.status); alert(XMLHttpRequest.readyState); alert(textStatus); } }); This is the end of this article about JavaScript solving parsererror errors in ajax. For more relevant JavaScript solving parsererror errors in ajax, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to open ports to the outside world in Alibaba Cloud Centos7.X
>>: Detailed example of using case statement in MySQL stored procedure
Table of contents 1. Filter, map, and reduce proc...
There were always problems when installing tortoi...
1. Install the express library and generator Open...
1. View existing modules /usr/local/nginx/sbin/ng...
The img tag in XHTML should be written like this:...
HTML forms are used to collect different types of...
I recently used Dreamweaver to make a product pres...
Today we are going to implement a Thunder Fighter...
Solution to MySql service disappearance for unkno...
TABLE> <TR> <TD> <TH> <CA...
Table of contents 1. Create a table 1.1. Basic sy...
The legend component is a commonly used component...
There are two ways to achieve read-only input: dis...
1. SHOW PROCESSLIST command SHOW PROCESSLIST show...
Table name and fields –1. Student List Student (s...