AJAX:只触发了错误回调

PJ1*_*405 6 javascript php ajax jquery curl

我已声明successerror回调,但在状态代码的情况下200它也只调用错误回调.

我一直在调用curl调用其他php文件registry.php.

这是我试过的:

$.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");
  }
});
Run Code Online (Sandbox Code Playgroud)

我在文档中读到我们没有明确地调用成功回调,希望它是正确的.

知道如何在200状态代码时调用成功回调.

RESPONSE 希望这会有所帮助,这是我从chrome控制台复制的,不是由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: ()
Run Code Online (Sandbox Code Playgroud)

小智 2

正如您所提到的,您正在curl向其他人打电话php,发生的情况是每当您拨打电话时curl,您都必须将 的响应返回curl给客户端。所以要转移callreturn的值curl,你必须设置一个选项curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);。这将解决您的问题。希望如此。