I used this to call ajax get request
// 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" );
});
})
and the response is error see here https://www.screencast.com/t/lI6UdQ5H
note: {auth_id} I already replace that with my auth_id provided by plivo.
Thanks for your help!
Your code seem to work. I have made a demo here. please check your ajax url.
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>