AJAX: only error callback was triggered

I declared success and error callbacks, but in the case of status code 200 also only calls error callbacks.

I am making a curl call to another php file inside registry.php .

Here is what I tried:

 $.ajax({ type: "POST" ,data: { action: "blah" ,mobileNo: that.mobNo ,token: that.key } ,url: "http://90.8.41.232/localhost/registry.php" ,cache: false ,dataType: "json" ,success: function (response) { console.log("success"); } ,error: function () { console.log("error"); } }); 

I read in the documentation that we should not explicitly refer to the callback, we hope that this will be correct.

Any idea how to call a success callback when it's a 200 status code.

REACTION hope this helps, I copied chrome from the console, and did not print console.log ().

 bort: (statusText) always: () complete: () done: () error: () fail: () getAllResponseHeaders: () getResponseHeader: (key) overrideMimeType: (type) pipe: () progress: () promise: (obj) readyState: 4 responseText: "{"success":"Mobile No 9535746622 is approved"} {"report":true}" setRequestHeader: (name,value) state: () status: 200 statusCode: (map) statusText: "OK" success: () then: () 
+6
source share
3 answers

As you already mentioned, you make a curl call for another php , which happens when you make a curl call, you need to return the curl response to the client. So, to pass the return value of the curl call, you must set the curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); option curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); . This sorts your problem. I hope so.

+2
source

First, check the real error you are getting (not sure if you are really getting 200 status?)

 error: function (err) { console.error("error"); console.log(err); console.log(err.stack); throw err; } 

Show us the resulting magazine.

+2
source

I did this a few weeks ago, and for me it works if I name it

 $.ajax( { type: "POST", data: { action: "blah", mobileNo: that.mobNo, token: that.key }, url: "http://90.8.41.232/localhost/registry.php", cache: false, dataType: json, }) .success (function (data, status, jqxhr) { // do your stuff }) .error (function(x, status, jqxhr) { // handle your errors }); 
-2
source

All Articles