ajax jquery简单获取请求

ajax jquery简单获取请求

问题描述:

我正在使用jquery ajax进行这个简单的get请求:

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"}

这是预期的结果。那么为什么不使用ajax呢?
谢谢!

which is the expected result. So why isn't it working using ajax? thanks!

在我看来,这是一个跨域问题,因为你不允许向另一个域发出请求。

It seems to me, this is a cross domain issue, since you're not allowed to make request to a different domain.

您必须解决此问题:
- 使用在您的服务器上运行的代理脚本,该脚本将提供您的请求,并将处理将其发送到浏览器

- 您提出请求的服务应该具有JSONP支持。这是一种跨域技术。您可能需要阅读此 http://en.wikipedia.org/wiki/JSONP