Home >Web Front-end >JS Tutorial >Jquery Ajax xmlhttp request success problem_jquery
I encountered an extremely strange problem today. I used various tools to check and saw that the server returned 200. The data was also normal, but $.ajax could not enter success. I was so depressed. I searched online.
FAQ scenarios:
1. Cross-domain;
2. $.ajax does not set dataType, and server side does not set response.ContentType
3. Json structure error;
The first and second ones were quickly eliminated. At the third time, I revisited the definition of Json: http://www.json.org/json-zh.html, and reviewed Json again. Definition:
Key-value pair: The key is string, and the value can be a string enclosed in double quotes, a number, true, false, null, object, or array. These structures can be nested.
The original defined type is
{isSuccess:true,message:'good'}
According to the definition of the key, it should be modified to
{'isSuccess':true,'message':'good'}
If it still doesn’t work if you continue to execute, modify it according to the definition of the value:
{'isSuccess':true,'message':"good"}
I am completely depressed, this is not enough
I will put it down here and take a closer look at the specifications for Json key values. The value must be defined as a string with double quotes. Why double quotes? What about the key? Is it necessary? Replace with
{"isSuccess":true,"message":"good"}
Got through directly.
This is the difference between the format of Json and the objects in Javascript. Json requires keys and values to be in double quotes! !