This is rather a syntax question I am going to explain it jQuery’s ajax functionality.
Let’s say I want to control dataType of all ajax request according to url. For example url’s with parameter &parseJSON=true should have a dataType of 'JSON' automatically.
For example:
$.myajax({url:'http://example.com&parseJSON=true'})
should be equivalent to
$.ajax({url:'http://example.com&parseJSON=true', dataType: 'JSON'})
Basically, I need to check for URL and add dataType parameter if needed.
You can do this with an ajax prefilter:
This doesn’t change anything about how you use
$.ajax,$.post, or$.getother than that you no longer have to specify the dataType if the url parameter is present.