|
|
| Programming tutorials - Simple ajax script (JavaScript) |
index.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <title>Ajax dynamic content</title>
- <script type="text/javascript" src="ajax.js"></script>
- </head>
- <body onload="ajax_function('divid','page.php')">
- <div id="divid">Please wait...</div>
- </body>
- </html>
ajax.js
- function ajax_function(id, page){
- var xmlHttp;
- try{
- xmlHttp=new XMLHttpRequest();
- }
- catch (e){
- try{
- xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch (e){
- try{
- xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch (e){
- alert("Your browser does not support AJAX!");
- return false;
- }
- }
- }
- xmlHttp.onreadystatechange=function(){
- if(xmlHttp.readyState==4){
- document.getElementById(id).innerHTML=xmlHttp.responseText;
- }
- }
- xmlHttp.open("GET",page,true);
- xmlHttp.send(null);
- }
page.php
- <?php
- phpinfo();
- ?>
|
 |
|