AJAX JSONP causes the callback parameter to be automatically added. How to remove this?

I have several services - with clean URLs

and each service call checks the URL pattern.

Now I am calling these URLs through AJAX from another server using the JSONP technique.

But when called, the callback and _(timestamp) parameters with the service URLs are automatically added.

The timestamp is removed by adding cache : true . But can not remove the callback parameter.

here is my AJAX call 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 I get 404 from the service side.

My service returns data as callbackMethod ({..JSON RESPONSE ...}) . This way it will automatically call function callbackMethod(data) in my script. I do not need this callback parameter in my url.

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

Help Plz.

+8
jquery jsonp ajax
source share
2 answers

You should set jsonp: false , not jsonpCallback: false . You must also explicitly set the jsonpCallback parameter to the jsonpCallback name that you expect to receive from the service.

Link: http://api.jquery.com/jQuery.ajax/

+11
source share
  • If you set the caching to true , you will cache the request request, and all subsequent JSONP calls will not return new data.

  • Without a callback, JSONP is unusable because there is no way to read the answer. Callback is the whole point of JSONP.

  • Your server must be configured to handle a JSONP request. The URL you select will not affect the client side. Therefore, your problem should be server side. Here you have to deal with it. This is not a jQuery problem.

If you use a custom callback, try this, but the custom callback does not match the removal of the callback:

  jsonpCallback : "callbackMethod" 
+1
source share

All Articles