有一个rest服务,我的代码大致是这样
$http.jsonp(url)
.then(function(data){
console.log(data)
},function(res){
console.log(res)
})
When there is no data in the database, the console network information displays status as 200
response return data
Information printed by console.log(res)
Why does the status displayed in the network be 200, but when printed it becomes 404, and the response data is not returned. Now I need to get returncode=-1 for judgment when there is no data in the database. How should I get this response?
The URL address needs to add ?callback=JSON_CALLBACK. The result of your Response is:
({"returnCode": "-1"})
。正常Response的结果是:/**/angular.callbacks._0({"found":12,"posts": []});
The following is an online example: angularjs-http-jsonp-service-example. Remove the callback query parameter and take a look at the result.
Why the status displayed by the developer tools is 200? It just means that the HTTP request is successful. Why is 404 returned?
Please refer to the AngularJS httpBackend source code for details.