0

Here is my code

var api = "http://199.175.xx.xxx:3000?jsoncallback=?";
    $.getJSON( api, {}).done(function( data ) {
        alert('h');
    });

but alert is never happening. I can see from network tab in inspector that request is being sent successfully and also response is the correct one but why alert is not firing inside done callback?

here is the inspector result enter image description here

12
  • 1
    Does the URL correctly use the jsoncallback parameter to add the callback name to the response? Commented Feb 24, 2014 at 16:43
  • P.S. The data parameter in $.getJSON is optional. You don't need to pass {}, you can just do ` $.getJSON(api)`. Commented Feb 24, 2014 at 16:45
  • @RocketHazmat How to check its adding parameter correctly or not Commented Feb 24, 2014 at 16:46
  • Check the network tab for the response data? What does it look like? JSONP should look like this: callback({"your": "data"}). Also, is it your API or is it a third-party one? Are you sure it should be jsoncallback=?? Commented Feb 24, 2014 at 16:49
  • 1
    There's your problem right there. It's not using the jsoncallback parameter in the response, like it's supposed to. Did you create this URL, or is it a third-party API? Commented Feb 24, 2014 at 16:56

1 Answer 1

1

Use it this way :

var api = "http://199.175.xx.xxx:3000?jsoncallback=?";
$.getJSON(api, function (data) {
    alert('h');
});

You don't need to use .done()here, as $.getJSON already comes with a callback function.

Source : $.getJSON

Sign up to request clarification or add additional context in comments.

1 Comment

He doesn't need .done(), but it should work just fine with it.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.