I have used ajax in the following way (this is a similar to how i am using ajax in my chat application); incrementer.php file on line # 34 simply prints an incremented value from the session
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <script language="javascript">
- function getAjaxObject(){
- try{
- ajaxRequest = new XMLHttpRequest();
- } catch (e){
- // Internet Explorer Browsers
- try{
- ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try{
- ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e){
- // Something went wrong
- alert("Your browser doesn't support ajax!");
- return false;
- }
- }
- }
- return ajaxRequest;
- }
- function startCounting(){
- var a=getAjaxObject();
- a.onreadystatechange = function(){
- if(a.readyState==4){
- var text=a.responseText;
- var e=document.getElementById('val');
- if(e){
- e.innerHTML=text;
- }
- }
- }
- a.open("GET", "incrementer.php", true);
- a.send(null);
- setTimeout(startCounting,1);
- }
- </script>
- </head>
- <body>
- <input type="button" value="Send Object" onclick="startCounting()" />
- <div id="val"> </div>
- </body>
- </html>