I am making this simple get request using jquery ajax:
$.ajax({
url: "https://app.asana.com/-/api/0.1/workspaces/",
type: 'GET',
success: function(res) {
console.log(res);
alert(res);
}
});
It's returning an empty string as a result. If i go to this link in my browser, i get:
{"status":401,"error":"Not Authorized"}
which is the expected result. So why isn't it working using ajax? thanks!
This question is related to
javascript
jquery
ajax
i think the problem is that there is no data in the success-function because the request breaks up with an 401 error in your case and thus has no success.
if you use
$.ajax({
url: "https://app.asana.com/-/api/0.1/workspaces/",
type: 'GET',
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
there will be your 401 code i think (this link says so)
You can make AJAX requests to applications loaded from the SAME domain and SAME port.
Besides that, you should add dataType JSON
if you want the result to be deserialized automatically.
$.ajax({
url: "https://app.asana.com/-/api/0.1/workspaces/",
type: 'GET',
dataType: 'json', // added data type
success: function(res) {
console.log(res);
alert(res);
}
});
var settings = {
"async": true,
"crossDomain": true,
"url": "<your URL Here>",
"method": "GET",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"username": "[email protected]",
"password": "12345678"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
var dataString = "flag=fetchmediaaudio&id="+id;
$.ajax
({
type: "POST",
url: "ajax.php",
data: dataString,
success: function(html)
{
alert(html);
}
});
Source: Stackoverflow.com