javascript - How to get the Response Code Error from $ajax? -


i code number, example 1 below:

(500).

and go through error able show "code", "requestid" , "message".

here examples of code , possible error may appear user.

code example:

<script type="text/javascript">     $(function() {         var params = {             // request parameters             "visualfeatures": "categories",             "details": "{string}",             "language": "en",         };          $.ajax({             url: "https://westus.api.cognitive.microsoft.com/vision/v1.0/analyze?" + $.param(params),             beforesend: function(xhrobj){                 // request headers                 xhrobj.setrequestheader("content-type","application/json");                 xhrobj.setrequestheader("ocp-apim-subscription-key","{subscription key}");             },             type: "post",             // request body             data: "{body}",         })         .done(function(data) {             alert("success");         })         .fail(function() {             alert("error");         });     }); </script> </body> </html> 

error code:

response 500  possible errors:  failedtoprocess  failed process image. timeout  image processing time out. internalservererror  internal server error.  application/json {         "code":"failedtoprocess",     "requestid":"b8d802cf-dd8f-4e61-b15c-9e6c5844ccbc",     "message":"could not extract image features" } 

the response code can retrieved this:

.fail(function(jqxhr, textstatus, errorthrown) {          alert(jqxhr.status);  }) 

other properties present, can read here: http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -