Opened 12 years ago
Closed 12 years ago
#8130 closed bug (invalid)
$.get incorrectly executes javascript files
Reported by: | dennydaugherty | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | ajax | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
According to the documentation $.get() will load the contents of the specified file, however if you try and $.get() a javascript file it will execute it. The expectation is that $.get() loads the contents of the file whereas only $.getScript() execute them.
I created the following HTML and Javascript files to test. Note the file being loaded with $.get() has an alert() in it that is incorrectly executed. Though everything else works as expected, the test.js file should be executed.
test.html
<!DOCTYPE html> <html> <head> <title>Testing jQuery.get() with Javascript Files</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script> <script type="text/javascript"> console.log('Loading test.js using $.get()'); $.get('test.js', function (data) { console.log('Finished loading test.js'); $('#test').html(data); }); </script> </head> <body> <code id="test"> </code> </body> </html>
test.js
alert('Hello world');
Change History (1)
comment:1 Changed 12 years ago by
Component: | unfiled → ajax |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
Thanks for taking the time to contribute to the jQuery project by writing a bug report.
After checking your bug report I came to the conclusion that this isn't a bug. If you read the jQuery.get() documentation directly at the beginning it says
jQuery.get( ... )
is a short hand forjQuery.ajax({ ... })
.If you read up on the
dataType
parameter in the jQuery.ajax() documentation it says:This applies directly to your report. You didn't specify the
dataType
property so jQuery guessed by the respones content-type that this is a javascript file, and thus executes it as described by the documentation. If you don't want that to happen you can set thedataType
parameter ofjQuery.get()
to "text".