Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX JSONP call automatically adding callback parameter. How to remove that?

Tags:

jquery

ajax

jsonp

I have few Services- with clean-URLs

and while calling each service, the URL pattern is being checked.

Now am calling those URLs via AJAX from another server using JSONP technique.

But, while calling, its adding callback and _(timestamp) parameters with service-URLs, automatically.

The timestamp parameter is removed- by adding cache : true . But cant remove the callback parameter.

here is my AJAX calling code-

$.ajax({
        type: 'GET',
        url : "http://test.com/test/services/getFollowMeHistory/1/1/50",
        dataType:'jsonp',
        cache : true,
        crossDomain : true,
        //jsonpCallback : false,

        error : function(XMLHttpRequest, textStatus, errorThrown) {
            alert("Error occured while loading Loads."+textStatus);
            }
        });
});

Its calling the URL as- http://test.com/test/services/getFollowMeHistory/1/1/50?callback=false and am getting 404 from service side.

My service is returning data as callbackMethod( {..JSON RESPONSE...} ). So, it will automatically call the function callbackMethod(data) in my script. i dont need that callback parameter in my URL.

Just need to remove the ?callback=... part from URL

Plz help.

like image 688
Avisek Chakraborty Avatar asked Jun 08 '12 19:06

Avisek Chakraborty


1 Answers

  1. If you set cacheing to true ie will cache the request response, and all subsequent JSONP calls will not return new data.

  2. Without the callback JSONP is unusable, because there is no way to read the response. The callback is the whole point of JSONP.

  3. Your server must be set up to handle a JSONP request. The url you send will not effect the client side. So your problem must be on the server-side. Which is where you should handle it. Making this not a jQuery problem.

If you are using a custom callback Try this, but a custom callback is not the same as removing the callback:

 jsonpCallback : "callbackMethod"
like image 155
Fresheyeball Avatar answered Oct 04 '22 17:10

Fresheyeball