make json vs jsonp request, depending on url

make json vs jsonp request, depending on url

So I have a function that is going to get a URL, and have to retrieve json data from that URL.

The URL _might_ be same-domain, and might be cross-domain.  If it's cross-domain, of course I want to do jsonp complete with the script-tag-to-load and such, but if it's same domain of course I want to do just xhr for efficiency.

So I _could_ write all my own logic for this.  Write logic to see if the url is cross-domain or not, and then make entirely different $.ajax() calls depending. (I think I need to use $.ajax() rather than $.getJSON() because I need a callback on failure, not just success).   If it is cross-domain, use dataType:jsonp, and make sure to supply a &callback.  If it's not cross-domain, dataType:json, and don't even bother supplying a callback.

But I'm thinking I don't have to do all this, JQuery will help me out. But I'm having trouble figuring out if this is true, or how.  What's the easiest way to get $.ajax() to make a dataType:json request if it's same-domain, but a dataType:jsonp request if it's cross-domain?

Thanks for any advice!