Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

ajax - Why do I get this 501 Not Implemented error?

I am performing the following AJAX call:

$(document).ready(function() {

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

});

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?

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.

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

alt text http://grab.by/grabs/b1a13d92a4fc69aa310880a5d7a06b95.png

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...