https://blog.csdn.net/mafan121/article/details/50832873
I encountered a problem recently. I sent an ajax request, the request was successful, and the status was 200, but the success event was not entered, and the error event was added to the error event.
code show as below:
- $.ajax({
- url:$WEB_ROOT_PATH+"/dataLevel/dataLevelCtrl.htm?BLHMI=findBasicDataLevel",
- type:"post",
- dataType:"json",
- async:false,
- success:function(data){
- var dataScore = data;
- },error:function(){
- alert( "Something went wrong!" );
- }
- });
The reason for the error: dataType: "json", and the data returned in the background does not conform to the json specification.
Solution: first set the dataType to text, so that you can enter the success method to see what the data data is.
My data is: {"success":success}, it can be seen that the second success is not wrapped in quotation marks and does not conform to the json specification, so it cannot be converted to a json object.
The solution after that is fine. One is to modify the background return value, and the other is to directly parse the value returned by text.