$.ajax({url: 'http://gmaps-samples-v3.googlecode.com/svn-history/r16/trunk/xmlparsing/util.js', dataType: 'script text text', crossdomain:'true', success: function(msg, status, obj){console.log(msg);console.log(status);console.log(obj)}, mimetype: 'text/plain', cache:false});
I have tried running the above code and variants of it – removing mimetype, cache, setting dataType to ‘script text’ and ‘script script text’.
Straight from the jQuery Docs:
multiple, space-separated values: As
of jQuery 1.5, jQuery can convert a
dataType from what it received in the
Content-Type header to what you
require. For example, if you want a
text response to be treated as XML,
use “text xml” for the dataType. You
can also make a JSONP request, have it
received as text, and interpreted by
jQuery as XML: “jsonp text xml.”
Similarly, a shorthand string such as
“jsonp xml” will first attempt to
convert from jsonp to xml, and,
failing that, convert from jsonp to
text, and then from text to xml
I am limited to making the dataType request of type ‘script’, or else I get a “…is not allowed by Access-Control-Allow-Origin” error. But by all rights, shouldn’t I be free to interpret it within jQuery however I want to? I’ve clearly requested it as text, yet msg – the returned data from the server – is always ‘undefined’ regardless of what I do.
Are there any workarounds for this, hacky or not?
EDIT: This code works in that it loads the JavaScript file and downloads it to the user’s browser. But I still can’t view it!
Security mechanisms in browsers prevent you from doing this, because it would allow you to steal users’ private information from other websites. If you are making the request to the same domain as your script is on, it will work. Otherwise you cannot make the request in JavaScript, and need to make it from a server instead.