0

I have a call to get a JSON object (it happens to be the contents of a Domino view), which I will then parse for display. The anonymous function has code in it, but that is not relevant here, for it never gets called. Stepping through in debug (I am using Chrome), execution skips straight from the $.get to the next line without ever entering the success handler. The behaviour is the same whether I use .get() or .getJSON().

$.get(strURL,
    function(data) {}
)

I have tested the URL, and confirmed via JSONLint that it is returning valid JSON. How can I determine what is causing the failure?

Tushar
  • 85,780
  • 21
  • 159
  • 179
Andrew Brew
  • 109
  • 6
  • 3
    `success` is a callback, it will only be called when the `GET` request completes. Not right after that lines execution. – BenM Dec 03 '15 at 04:23
  • 2
    Does the web inspect show the XHR request being made? Check the Network tab. – Ohgodwhy Dec 03 '15 at 04:24
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Phil Dec 03 '15 at 04:31
  • Use firefox `firebug` plugin and see, if your http request gets a proper response... –  Dec 03 '15 at 04:32

3 Answers3

2

AJAX request can not successfully retrieve data from a different domain, sub domain, port, or protocol. Are you trying to access data from different domain?

Another suggestion would be try adding code to capture other events as showed below

$.get(strURL, function(data) {  alert( "success" );})
.done(function() {alert( "second success" );})
.fail(function() {alert( "error" );})  
.always(function() {    alert( "finished" ); });
Gajendra Naidu
  • 395
  • 3
  • 16
  • .fail gets a jqXHR object from which you can get the error details. – artm Dec 03 '15 at 04:40
  • Thanks, but no. The source is on the same host. I have tried adding the .fail function, but while that tells me *that* it has failed it does not tell me *why* it has failed. – Andrew Brew Dec 03 '15 at 04:51
1

Ohgodwhy's advise to examine the "Network" tab gave me what I wanted - not a jQuery problem after all, but rather a matter of familiarity with the Chrome dev tools.

Thank you!

Andrew Brew
  • 109
  • 6
0

You can get a response but that is not JSON, for example "No document Found" as you are using Domino. You can get detail about error by using responseText property.

.fail(function( jqXHR, textStatus, error ) {
  alert( "Request failed: " + textStatus + " responseText: " + jqXHR.responseText);
});

NB this is almost what says @artm, just givin here code of this.

cjmling
  • 6,896
  • 10
  • 43
  • 79
Emmanuel Gleizer
  • 1,990
  • 16
  • 26