0

Our server is located in europe. Now and then an american based user reports a problem when he uses the $.getJSON function.

His browser just displays the json response instead of catching it and passing it to javascript.

The ajax call just looks like:

$.getJSON(url, function(json_data){ ... });

Any ideas?

More info:

  1. The the same user has the problem in FF and IE.
  2. I use Ruby On Rails render :json. which response type is application/json.
Jonathan M
  • 16,131
  • 8
  • 49
  • 88
Tom Maeckelberghe
  • 1,890
  • 3
  • 21
  • 24

1 Answers1

2

Try using the $.ajax() method so you can handle errors and debug the success callback.

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        data: {},
        dataType: "json",
        url: url,
        success: function(json_data) {
            // parse json_data object
        },
        error: function (xhr, status, error) {
            // check for errors                
        } 
    });

Aside from that using an XHR viewer like Firebug or Chrome's built-in utility (CTRL+SHIFT+I) can be very helpful.

XHR DOM reference: http://www.w3schools.com/dom/dom_http.asp

Terry
  • 13,683
  • 8
  • 52
  • 78