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

瘦欲@ 提交于 2019-12-21 03:52:31

问题


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.


回答1:


You should set jsonp: false and not jsonpCallback: false. You should also explicitly set the jsonpCallback option to the callback name you expect to receive from the service.

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




回答2:


  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"


来源:https://stackoverflow.com/questions/10955213/ajax-jsonp-call-automatically-adding-callback-parameter-how-to-remove-that

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!