Jeni Jeni - 1 month ago 5x
jQuery Question

Uncaught ReferenceError: jQuery22303175114964962158_1470743444495 is not defined in JSONP AJAX request

I am making an AJAX request to get some data from server. In order to limit the request (due to large amount of requests will break the server) I have set timeout for the request. I am getting an error:

Uncaught ReferenceError: jQuery22303175114964962158_1470743444495 is not defined

Can anyone please help me to fix

url: url, // some url link here
type: "GET",
contentType: "application/jsonp; charset=utf-8",
dataType: 'jsonp',
timeout: 5000,
success: function(data, status) {
// some stuffs
error: function (xhr, status, error) {
// some stuffs

I have referred to this link.
and tried adding property like
. But it doesn't work for me.

Thanks in advance.


This is happening because the request is taking longer than your specified timeout limit. When a request takes longer than the timeout limit, the request is considered a failure and should never complete. If you want to tolerate requests that take longer than five seconds to complete, you should specify a higher timeout value (or leave it out entirely, if you can accept waiting indefinitely).

JSONP works by loading a file in a <script> element of the form

jQuery22303175114964962158_1470743444495({ some: "data" });

This causes a function called jQuery22303175114964962158_1470743444495 to run, with some data as an argument. jQuery automatically sets up a function called jQuery22303175114964962158_1470743444495 when it requests that script file from the server (which is a function that ultimately calls your success function). However, when you set a timeout, jQuery removes that function when the timeout time window ends, so you see the error jQuery22303175114964962158_1470743444495 is not defined because the <script> loads, but the function it calls no longer exists after five seconds.

Suppose I wanted my friend to come by my house to give me a screwdriver. We have the following exchange over the phone:

ME: Hi, friend! Please let me borrow your screwdriver. Can you drop it off at my house?

FRIEND: I'd love to. Where can I leave it?

ME: I am putting a purple basket on my porch. Please leave it in there.

Since you are setting a timeout, in this analogy you also decide to remove the purple basket after waiting five hours. When your friend shows up six hours later, he doesn't see the purple basket (because you took it back inside an hour before) and says

FRIEND: Error: purple basket not found!

The solution here is, of course, not to remove the purple basket (i.e., don't set a timeout value) unless you really have a good reason to reject responses after a fixed period of time. If you do have a good reason to reject responses after a fixed period of time, then it's not a problem if your requests fail after that period of time: it's exactly what you asked for.

Since you don't want your requests to always fail after five seconds, don't set a timeout: 5000 which causes your requests to fail after five seconds.