问题
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:
If you set cacheing to
true
ie will cache the request response, and all subsequent JSONP calls will not return new data.Without the callback JSONP is unusable, because there is no way to read the response. The callback is the whole point of JSONP.
- 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