alwaysme Posted February 26, 2009 Share Posted February 26, 2009 Hello there, I find a little script on the net for ajax which loads hello.html (pageone), but lets say i want another link that loads statistics.html, how do i do that? this is the code <script type="text/javascript"> var http = false; if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); } function replace() { http.open("GET", "hello.html", true); http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById('pageone').innerHTML = http.responseText; } } http.send(null); } </script></head> <body> <p><a href="javascript:replace()">page one</a></p> <div id="pageone"> Hello, world! </div> </body> like i need another link (maybe more later) where each load different page, now i can only load one page with the above... i.e <p><a href="javascript:replace()">page one</a></p> // this takes me to hello.html (working) <p><a href="javascript:replace()">page two</a></p> //this take me to statistics.html how can i make that? Link to comment https://forums.phpfreaks.com/topic/146963-novice-ajax-question/ Share on other sites More sharing options...
corbin Posted February 26, 2009 Share Posted February 26, 2009 Pass the URL as a variable to replace. Link to comment https://forums.phpfreaks.com/topic/146963-novice-ajax-question/#findComment-771520 Share on other sites More sharing options...
alwaysme Posted February 26, 2009 Author Share Posted February 26, 2009 hello, thanks but can you please teach me that in the above code? Link to comment https://forums.phpfreaks.com/topic/146963-novice-ajax-question/#findComment-771685 Share on other sites More sharing options...
lordphate Posted March 2, 2009 Share Posted March 2, 2009 Hey Always <script type="text/javascript"> var http = false; if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); } function replace() { http.open("GET", "hello.html", true); http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById('pageone').innerHTML = http.responseText; } } http.send(null); } function replace2() { http.open("GET", "statistics.html", true); http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById('pageone').innerHTML = http.responseText; } } http.send(null); } </script></head> <body> <p><a href="javascript:replace()">page one</a></p> <p><a href="javascript:replace2()">page one</a></p> <div id="pageone"> Hello, world! </div> </body> Link to comment https://forums.phpfreaks.com/topic/146963-novice-ajax-question/#findComment-774624 Share on other sites More sharing options...
corbin Posted March 2, 2009 Share Posted March 2, 2009 Blerh.... Forgot about this thread. Variables in Javascript are very, very, very straight forward. function somefunction(somevar) { //somevar is now what ever value is passed into the function } function replace(url) { http.open("GET", url, true); //blah } Link to comment https://forums.phpfreaks.com/topic/146963-novice-ajax-question/#findComment-775039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.