1

I am attempting to make a jsonp call with jQuery 1.7 but when the call returns I get the following error:

Uncaught TypeError: Object function ( response ) { responseContainer = [ response ]; } has no method 'json'

When inspecting the data being returned I noticed that '.json' is being appended to the callback function name:

jQuery17206211688306648284_1336426518269.json({"..."})

Here is the code that is making the request:

$.ajax({
  url: "...",
  dataType: 'jsonp',
  success: function(data) {
    return console.log(data);
  }
});

Answer:

As adeneo said the server was trying to specify a callback function of 'json' this is handled by setting the following parameter on the $.ajax call:

jsonpCallback: 'json'
2
  • 1
    Then it would seem that your server is adding .json to the function name provided by jQuery. Therefore, when the script runs, the jQuery17206211688306648284_1336426518269 function is found, and it tries to look up a .json property on the function object, and invoke it as if it was a method of the object. Commented May 7, 2012 at 21:47
  • Try this. Add jsonpCallback: 'foo' to your request, and create an object in global scope. window.foo = { json: function(data) { console.log(data);} }; I'm betting the server will return foo.json({"..."}), invoking the object/method you created. Commented May 7, 2012 at 23:23

1 Answer 1

2

jQuery's $.ajax function automagically adds a callback function to jsonp requests, but it looks like the json() function you are seeing is added by the server, but you could try :

$.ajax({
  url: "...",
  dataType: 'jsonp',
  jsonp: false,
  success: function(data) {
    return console.log(data);
  }
});

To disable the jQuery auto callback thingy, or just create an empty chainable function with the name json()

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

3 Comments

I guess I don't understand where the .json is being appended. This is a request being made from client side javascript so it shouldn't be routed through my server at all. The remote url is from a third-party and I'ved tried it different apis all appending the .json
Yes, it's not your server per se, but the server that sends back the jsonp result that has a callback function named json(), if i remember correctly this site (SO) has something similar, where the callback name also is specified in the returned result, for sites that does not specify a callback function, jQuery built in magic is useful.
Your were correct the server was trying to specify a callback name of 'json'. I was able to fix it by setting: jsonpCallback: 'json'. Thank You!

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.