Saturday, May 11, 2019

javascript - ajax jquery simple get request



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!


Answer



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


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...