srini
srini

Reputation: 89

Jquery .html() and jquery .load

I have a page which is divided in to many tabs , with each tab pulling data from another pages through ajax.

After the ajax call, i use a .html ( data ) where data is the html of called page to insert it in to the tab. My question is , if the called page has javascript functions , will those be executed and resultant data is sent or just the html page is sent?

Kindly help.

Thanks.

Upvotes: 2

Views: 165

Answers (2)

Chris Cashwell
Chris Cashwell

Reputation: 22859

What is returned by the server is different from what is displayed on the page. The file you receive back isn't processed before Jquery touches it. However, as soon as Jquery receives it, the scripts are subsequently executed. So no, the scripts are not run prior to Jquery's receipt of the contents.

Upvotes: 1

Dave
Dave

Reputation: 11879

Yes, as long as you are specifying:

dataType: "html",

inside your ajax call.

From http://api.jquery.com/jQuery.ajax/ :

If html is specified, any embedded JavaScript inside the retrieved data is executed before the HTML is returned as a string. Similarly, script will execute the JavaScript that is pulled back from the server, then return nothing.

Upvotes: 1

Related Questions