Detailed explanation of the parsererror error case in JavaScript solution in ajax

Detailed explanation of the parsererror error case in JavaScript solution in ajax

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:
  • Ajax solves cross-domain problem by setting CORS response header to achieve cross-domain case study
  • Three-level linkage provincial and municipal ajax code
  • JSON, AJAX, Maven Basics
  • Ajax login verification implementation code
  • Ajax realizes the linkage between provinces, cities and districts
  • jQuery+Ajax to achieve simple paging effect
  • Preliminary implementation of Ajax (using vscode+node.js+express framework)
  • How to use AJAX to obtain Django backend data

<<:  How to open ports to the outside world in Alibaba Cloud Centos7.X

>>:  Detailed example of using case statement in MySQL stored procedure

Recommend

TortoiseSvn Little Turtle Installation Latest Detailed Graphics Tutorial

There were always problems when installing tortoi...

The whole process of node.js using express to automatically build the project

1. Install the express library and generator Open...

Nginx compiled nginx - add new module

1. View existing modules /usr/local/nginx/sbin/ng...

Things to note when writing self-closing XHTML tags

The img tag in XHTML should be written like this:...

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of...

How to remove the blue box that appears when the image is used as a hyperlink

I recently used Dreamweaver to make a product pres...

How to use VUE and Canvas to implement a Thunder Fighter typing game

Today we are going to implement a Thunder Fighter...

Solution to MySql service disappearance for unknown reasons

Solution to MySql service disappearance for unkno...

Comprehensive summary of MYSQL tables

Table of contents 1. Create a table 1.1. Basic sy...

Echarts legend component properties and source code

The legend component is a commonly used component...

Set the input to read-only via disabled and readonly

There are two ways to achieve read-only input: dis...

MySQL SHOW PROCESSLIST assists in the entire process of troubleshooting

1. SHOW PROCESSLIST command SHOW PROCESSLIST show...

Mysql Sql statement exercises (50 questions)

Table name and fields –1. Student List Student (s...