How do I doa Jquery.get on a JS file without executing it?

774 views Asked by At

So I'm trying to make an Ajax request to pull down a js file, just to check the version number recorded inside its comments. However, if I run a jQuery.get, and the file pulled down is a javascript it automatically executes it, when I DON'T want the JS to be executed, I just want to read it and look at parts of the text of the script. How do I alter this:

 jQuery.get("somefile.js", function(data) { console.log("Do stuff here.") });

So that I can run that success handler WITHOUT first executing somefile.js?

1

There are 1 answers

0
James Hibbard On

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");

See here: Jquery get javascript file without running