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!!

1 Answer 1

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
  });

  };
2
  • 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!! Commented Sep 12, 2011 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
    Commented Sep 12, 2011 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.