The ajax request returns a status of 200 but still enters the error event

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:

[javascript]  view plain copy  
  1. $.ajax({  
  2.     url:$WEB_ROOT_PATH+"/dataLevel/dataLevelCtrl.htm?BLHMI=findBasicDataLevel",  
  3.     type:"post",  
  4.     dataType:"json",  
  5.     async:false,  
  6.     success:function(data){  
  7.         var  dataScore = data;  
  8.     },error:function(){  
  9.         alert( "Something went wrong!" );  
  10.     }  
  11. });  

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.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325399672&siteId=291194637