为什么我得到这个501未执行错误?错误

由网友(两行清泪相思病)分享简介:我执行以下AJAX调用:I am performing the following AJAX call:$(document).ready(function() {$.getJSON('https://sendgrid.com/api/user.stats.json',{'api_user': 'me@mydoma...

我执行以下AJAX调用:

I am performing the following AJAX call:

$(document).ready(function() {

  $.getJSON('https://sendgrid.com/api/user.stats.json',
    {
      'api_user': 'me@mydomain.com',
      'api_key': 'MYAPIKEY',
      'user': 'me@mydomain.com',
      'category': 'MY_CATEGORY'
    },
    function(response){
      alert('received response');
    }
  );

});

和我没有得到任何警告信息的预期。相反,萤火虫说,我得到501未实现。

and I get no alert message as expected. Instead, Firebug says I get "501 Not Implemented."

为什么呢?什么我需要做的,解决这个问题?

Why? What do I need to do to fix this?

如果我去的URL对应于Firebug的AJAX调用,我得到一个JSON文件的下载,它包含了预期的数据。

If I go to the URL corresponding to the AJAX call in Firebug, I get a JSON file as a download, and it contains the expected data.

有一件事我注意到的是,萤火说OPTIONS而不是GET:

One thing I've noticed is that firebug says OPTIONS instead of GET:

推荐答案

我不知道这是否是相关的,但一般的客户端在不同的领域,要求JSON到服务器时,您需要使用JSONP而不是JSON的因同源策略。因此他们必须期待您与您的服务器的网站进行交互 - 不幸的是,它没有自己的API支持使用JSONP出现。在这种情况下,你需要代理的方法在服务器上翻译的调用他们的API,以便客户端调用在同一个域中的页面向服务器。

I don't know if this is related, but generally when requesting JSON on the client to a server in a different domain you'll need to use JSONP instead of JSON due to the Same Origin Policy. Unfortunately, it doesn't appear that their API supports using JSONP -- so they must expect you to interact with their site from your server. In that case you'll need proxy methods on your server to translate the calls to their API so that the client calls are made to a server in the same domain as the page.

阅读全文

相关推荐

最新文章