Chito Adinugraha
Chito Adinugraha

Reputation: 1320

Jquery get javascript file without running

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

Answers (2)

jfriend00
jfriend00

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

Syed Abdul Qadeer
Syed Abdul Qadeer

Reputation: 465

have you tried using the load() method of the Jquery.

http://api.jquery.com/load/

Upvotes: -1

Related Questions