2

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.

srini
  • 89
  • 4
  • 15
  • What do you mean will those be executed and resultant data sent ? JS is executed client side not server side. – aziz punjani Sep 09 '11 at 20:49
  • I meant if its the programmer's responsibility to execute the script after the html is returned by jquery ajax or the load/html in jquery will take of executing the js code!! sorry to have used confusing words.. – srini Sep 09 '11 at 21:59

2 Answers2

1

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.

Dave
  • 9,886
  • 4
  • 31
  • 46
1

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.

Chris Cashwell
  • 20,898
  • 13
  • 60
  • 91
  • I understood that. can you take a look at my post http://stackoverflow.com/questions/7366610/jqgrid-not-rendered-when-the-html-page-containing-the-grid-is-loaded-through-an-a the jqgrid that is formed in a function isn't rendered at all in the main page. thank you – srini Sep 09 '11 at 21:26