Jump to content

execute JavaScript in ajax requested page


johnnyg24

Recommended Posts

I have a webpage, lets call it page1.asp, that dynamically builds the page using request.form variables. After page1.asp loads, JavaScript takes the build page, copies it and sends it to another page, via ajax, to be emailed from our server. I'm trying to utilize page1.asp within another application. So now I am trying to pass page1.asp form variables via ajax. So far page1.asp is build properly but the JavaScript on page1.asp will not execute therefore, nothing gets emailed. Is there a way to execute this JavaScript when calling page1.asp via ajax? I've read a little on using the eval() function but I'm not trying to execute the script from page1.asp on the new calling page. In fact, the new page doesn't even do anything with the response, I'm just trying to email a web page behind the scenes. Thanks.

Link to comment
Share on other sites

It won't work to use ajax to receive a complete page with both HTML and Javascript and expect the Javascript to get executed. Using eval is the way to execute Javascript code that was returned from an ajax request, but eval doesn't work with Javascript embedded in surrounding HTML markup. When an ajax response does need to include both HTML markup and also Javascript that needs to get executed they are typically in separate sections where the HTML can be added to the page somewhere, and the Javascript can be executed with eval. The only alternative I can think of is to parse the HTML to extract all of the Javascript and execute it, but that's not going to work well with the surrounding HTML.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...