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!
get() method requests data from the server with an HTTP GET request. Syntax: $. get(URL,callback); The required URL parameter specifies the URL you wish to request.
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);
}
});
http://api.jquery.com/jQuery.ajax/
It seems to me, this is a cross-domain issue since you're not allowed to make a request to a different domain.
You have to find solutions to this problem: - Use a proxy script, running on your server that will forward your request and will handle the response sending it to the browser Or - The service you're making the request should have JSONP support. This is a cross-domain technique. You might want to read this http://en.wikipedia.org/wiki/JSONP
var dataString = "flag=fetchmediaaudio&id="+id;
$.ajax
({
type: "POST",
url: "ajax.php",
data: dataString,
success: function(html)
{
alert(html);
}
});
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);
});
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With