php - Executing javascript script after ajax-loaded a page - doesn't work -


i'm trying page ajax, when page , includes javascript code - doesn't execute it.

why?

simple code in ajax page:

<script type="text/javascript"> alert("hello"); </script> 

...and doesn't execute it. i'm trying use google maps api , add markers ajax, whenever add 1 execute ajax page gets new marker, stores in database , should add marker "dynamically" map.

but since can't execute single javascript function way, do?

is functions i've defined on page beforehand protected or private?

** updated ajax function **

function ajaxexecute(id, link, query) {     if (query != null)     {         query = query.replace("amp;", "");     }      if (window.xmlhttprequest)     {         // code ie7+, firefox, chrome, opera, safari         xmlhttp=new xmlhttprequest();     }     else     {         // code ie6, ie5         xmlhttp=new activexobject("microsoft.xmlhttp");     }      xmlhttp.onreadystatechange=function()     {         if (xmlhttp.readystate==4 && xmlhttp.status==200)         {             if (id != null)             {                     document.getelementbyid(id).innerhtml=xmlhttp.responsetext;             }         }     }      if (query == null)     {         xmlhttp.open("get",link,true);     }     else     {         if (query.substr(0, 1) != "?")         {             xmlhttp.open("get",link+"?"+query,true);         }         else         {             xmlhttp.open("get",link+query,true);         }     }     xmlhttp.send(); } 

** solution deukalion **

var content = xmlhttp.responsetext;  if (id != null) {      document.getelementbyid(id).innerhtml=content;     var script = content.match("<script[^>]*>[^<]*</script>");      if (script != null)     {         script = script.tostring().replace('<script type="text/javascript">', '');         script = script.replace('</script>', '');         eval(script);      } } 

and on events, had within script addevent listeners instead of making "select onchange='executefunctionnotincludedinajaxfile();'" had addeventlistener("change", functionname, false) this. in script being evaluated.

when update page doing setting container's innerhtml updated content, browser not run scripts in it. can locate <script> tags, innerhtml (ie may prefer innertext), , eval() scripts (which pretty jquery does, though finds scripts regex before updating dom).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -