Load javascript files with ajax -



Load javascript files with ajax -

just simple question. (probably basic quess)

using xmlhttp able load page, not sure how iclude js files..

how can alter code in images below, able include 2 java script files page loaded ajax? i'm far not java script programmer, needs help.

thank you.

clientside.php: <html> <head> <title></title> <script src="xmlhttp.js"></script> <script> var urlserver ="serverside.php"; var xmlobj = null; function callserver(urlserver){ xmlobj= xmlhttp.create(); if(xmlobj) { xmlobj.onreadystatechange = responsefromserver; xmlobj.open("get", urlserver, true); xmlobj.send(); } } function responsefromserver() { if (xmlobj.readystate == 4) { if (xmlobj.status == 200) { document.getelementbyid("main").innerhtml = xmlobj.responsexml.getelementsbytagname("mybody")[0].firstchild.nodevalue; eval(xmlobj.responsexml.getelementsbytagname("myscript")[0].firstchild.nodevalue); } } } </script> </head> <body> <div id="main"></div> <input type="button" value="begin test" onclick="callserver(urlserver)"> </body> </html> serverside.php : <?php //how load these 2 javascript files <body> below. //obviously method below not work.. $script=" <script type='text/javascript' src='slimbox/js/mootools.js'></script> <script type='text/javascript' src='slimbox/js/slimbox.js'></script> "; $body=" <body> <a href='img/facebook-icon.png' rel='lightbox[roadtrip]' cap='test'><img alt=''border='0' src='img/facebook-icon.png' /></a> </body> "; //now build xml page: $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $xml .= "<mypage>"; $xml .= "<myscript>".htmlentities($script)."</myscript>"; $xml .= "<mybody>".htmlentities($body)."</mybody>"; $xml .= "</mypage>"; header('content-type: text/xml'); echo $xml; ?>

most efficient way utilize ajax load script source(uri) , utilize javavcript update script source

something like:

document.getelementbyid('external_script').src = 'http://cross.domain.com/other.js';

fore more on how load script dynamically check

javascript ajax

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -