2

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.