Reputation: 1320
I want to get content of a file using jquery, normally i can use:
$.get("file", function(data) { alert(data) }
When i try to get javascript file, jquery run the javascript code before returning callback.
How to get file content without running its code?
Upvotes: 2
Views: 1355
Reputation: 707486
Set the dataType
argument to $.get()
to "text"
to tell jQuery that the data is a string and it should not guess the type.
$.get("file", function(data) { alert(data) }, "text");
$.get()
is just a shortcut for $.ajax()
and you can see in the $.ajax()
documentation that the dataType
argument has a number of values you can pass to the ajax call. The default is an intelligent guess which probably figures out that it's a script so it executes it. One of the possibilities is "text"
which sounds like what you want.
Upvotes: 6