2017-09-19 70 views
0

我用這個叫AJAX get請求Plivo得到不使用jQuery GET請求工作的所有活呼叫

 // Assign handlers immediately after making the request, 
     // and remember the jqxhr object for this request 
     var jqxhr = $.get("https://api.plivo.com/v1/Account/{auth_id}/Call/?status=live", function(data) { 
      console.log("success" + data); 
     }) 

     .done(function(data) { 
      console.log("second success"); 
     }) 

     .fail(function(data) { 
      console.log("error"); 
     }) 
     .always(function(data) { 
      console.log("finished"); 
      console.log(data); 
     }); 

     // Perform other work here ... 

     // Set another completion function for the request above 
     jqxhr.always(function() { 
      alert("second finished"); 
     }); 
    }) 

和響應是錯誤在這裏看到https://www.screencast.com/t/lI6UdQ5H

注:已經 {AUTH_ID}我用我的autiv_id由plivo提供。

感謝您的幫助!

回答

0

你的代碼似乎工作。我在這裏做了一個演示。請檢查你的ajax網址。

https://jsfiddle.net/aquadk/ez8Lae5v/3/

function mylogger(aValue) { 
    var theDiv = document.getElementById("msg"); 
    theDiv.innerHTML += aValue + '<br>' 
     //console.log("second success"); 
    } 
    var USERNAME = 'userid'; 
    var PASSWORD = 'pass' 
    // Assign handlers immediately after making the request, 
    // and remember the jqxhr object for this request 
    var jqxhr = $.ajax({ 
    type: "GET", 
    url: "https://api.plivo.com/v1/Account/{auth_id}/Call/?status=live", 
    dataType: 'json', 
    async: false, 
    headers: { 
     "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD) 
    }, 
    success: function() { 
     mylogger("success" + data); 
    } 
    }) 

    .done(function(data) { 
    mylogger("second success"); 
    }) 

    .fail(function(data) { 
     mylogger("error"); 
    }) 
    .always(function(data) { 
     mylogger("finished"); 
     mylogger(data); 
    }); 

    // Perform other work here ... 

    // Set another completion function for the request above 
    jqxhr.always(function() { 
    mylogger("second finished"); 
    }); 

HTML

<Div id="msg"> 

</Div> 
+0

@Rene嗨,感謝您的幫助。我測試過,不應該顯示錯誤消息,但成功或什麼反應。 –

+0

您是否嘗試過更改我的代碼中的網址 –

+0

是的,我試過了,回覆與您的相同。 –