1

I want to include a function on my page, that checks whether the user has a Gravatar account with their email. If yes, they should have that picture displayed, if not they should be given other options.

I'm trying to do this as follows:

  $.ajax({
      url: 'https://secure.gravatar.com/' + md5(user.email) + '.json',
      method: 'GET',
      timeout: 4000,
      success: function successFn() {
          doGravatarStuff();
      },
      error: function errorFn(response, status, error) {
          console.log(response.status); //debug
      }
  });

This always returns an error status of 0 on Internet Explorer and I can't seem to figure out why. I tried changing the 'dataType' to 'json', 'html' etc but that doesn't seem to help.

Also, and maybe that is a related problem, if I test this on FF or Crome, with a user that really doesn't have an account, it returns a 404-error according to the 'net' tab readout

404 Not Found 649ms

but 'response.status' still seems to be 0

Any ideas anyone? Thanks so much in advance!!

HumanCatfood
  • 960
  • 1
  • 7
  • 20

1 Answers1

5

Normally cross-domain AJAX requests are denied because it's a security thing. See this blog article: http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

Did you try the jsonp dataType? I use jsonp when I access twitter's tweet json feed.

Example:

var urls = "http://twitter.com/status/user_timeline/" + username + ".json?count=" + pageSize + "&page=" + currentPage;

  $.ajax({
    beforeSend: function () {
      $("#ajax-load").fadeIn()
    },
    url: urls,
    cache: true,
    type: 'GET',
    dataType: 'jsonp',
    success: twitterCallback2
  });

  };
Benno
  • 3,008
  • 3
  • 26
  • 41
  • Hey, it works now. I had tried JSONP before but it hadn't worked. Presumably I put in a typo or something. Anyway, it works fine now, thanks! *acceptify!!* – HumanCatfood Sep 12 '11 at 10:10
  • Yeah potentially, I think JSONP is a little antsy when it comes to the response? _"As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually **fail silently**."_ Might have run into that issue. Thanks =) – Benno Sep 12 '11 at 12:41