Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script data type in jquery

Tags:

jquery

On jquery site it says:

"script": Evaluates the response as JavaScript and evaluates it.

I get a block of js code (with no script tags around it) thru an ajax call and a chunk of mark up. For the mark up to work i need the js code to be executed as soon as it's got. Do I have to append the JS code to the dom for it to get executed or as it says on the jquery site, it just gets executed by itself as soon as it's got?

Can someone help me on this please?

Thanks, L

like image 979
lshettyl Avatar asked Jun 18 '26 01:06

lshettyl


1 Answers

If you're referring to jQuery.getScript(), it should execute the code returned by the function immediately. In fact, according to the docs, there is a callback parameter you can specify, and this callback is passed the loaded script, but the loaded script will already be executed before the callback is called. So you don't have to do anything or add it to the DOM, it will execute as soon as it is downloaded. Also, no script tags are needed just like in an external .js file.

like image 166
Surreal Dreams Avatar answered Jun 19 '26 15:06

Surreal Dreams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!