How can I tell jQuery to automatically use "jsonp" for cross-domain ajax requests while it keeps using "json" for same-domain requests? I want to write a client library in javascript which uses jsonp only when necessary. Let's take this small snippet as an example:
jQuery.ajax(url, {
dataType: "jsonp"
});
When data type is "jsonp" then jquery always uses jsonp but already automatically detects if it can send a normal Ajax request (for same-domain requests) or if it has to use javascript injection (for cross-domain request).
So it seems jQuery is already able to auto-detect this and decides which technique to use. But it is not necessary to use jsonp when a standard Ajax request is possible so I want to use "jsonp" only for cross-domain requests. How can I do this?
Or maybe it is possible to ask jQuery if a url is cross-domain or not? Then I could check this myself and call jQuery.ajax with different data types.