JSONP stands for JSON with padding. All the browsers follow the same origin policy. You can not send XMLHttpRequest to other domain. To prevent this security, we need to use the JSONP in ajax request. When we request a ajax call to the remote server then data coming in response will be wrapped in function callback. When ajax request is completed then the callback function added in Html DOM is invoked by the result. JSONP only supports $_GET method.
In case of JSONP we get the response as object and pass the object as argument in callback function. This is the reason that we attach the callback parameter in ajax request so that server will be know the function to wrap the response. In JSONP parse error will not be catchable.
<script>
jQuery(function($){
var dataval = {
'number':1
};
ajax({
url:'http://otherdomain.com',
data:dataval,
dataType:'JSONP',
success:function(result){
console.log(result);
}
});
});
</script>
0 Comment(s)