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
1. Download the software 1. Go to the MySQL offic...
Environment Preparation Docker environment MySQL ...
What are the attributes of the JS script tag: cha...
Preface The previous article introduced the insta...
I used ECharts when doing a project before. Today...
Enter the /etc/yum.repos.d/ folder Create rabbitm...
Configure service startup and shutdown in Linux s...
This article example shares the specific code of ...
1. Introduction to MariaDB and MySQL 1. Introduct...
This time, we will try to package the running con...
view: Views in MySQL have many similarities with ...
Table of contents Preface keep-avlive hook functi...
Table of contents What are hooks? Class Component...
Table of contents Download the compressed file Ad...
Table of contents 1. Pull the image 2. Create a R...