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
This article describes how to use the local yum s...
Table of contents Function Basic query functions ...
Vue bus mechanism (bus) In addition to using vuex...
Table of contents Virtual DOM What is virtual dom...
Preface Usually, a "paging" strategy is...
Sometimes we need to control whether HTML elements...
Table of contents Exporting Docker containers Imp...
When you start working on a project, it’s importa...
Database backup #grammar: # mysqldump -h server-u...
#mysql -uroot -p Enter password mysql> show fu...
The following CSS class names starting with a num...
Reasonable setting of MySQL sql_mode sql_mode is ...
Table of contents 1. Initialize the map 2. Map Po...
@vue+echarts realizes the flow effect of China ma...
Copy code The code is as follows: <!DOCTYPE ht...