News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Creating an XMLHttpRequest Object

Started by ben2ong2, October 06, 2006, 04:35:19 PM

Previous topic - Next topic

0 Members and 6 Guests are viewing this topic.

ben2ong2

For Mozilla, Firefox, Safari, Opera, and Netscape:
var xmlhttp=new XMLHttpRequest()
For Internet Explorer:
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
Example
<script type="text/javascript">var xmlhttpfunction loadXMLDoc(url){xmlhttp=null// code for Mozilla, etc.if (window.XMLHttpRequest)  {  xmlhttp=new XMLHttpRequest()  }// code for IEelse if (window.ActiveXObject)  {  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")  }if (xmlhttp!=null)  {  xmlhttp.onreadystatechange=state_Change  You are not allowed to view links. Register or Login("GET",url,true)  xmlhttp.send(null)  }else  {  alert("Your browser does not support XMLHTTP.")  }}function state_Change(){// if xmlhttp shows "loaded"if (xmlhttp.readyState==4)  {  // if "OK"  if (xmlhttp.status==200)    {    // ...some code here...    }  else    {    alert("Problem retrieving XML data")    }  }}</script>
Note: An important property in the example above is the onreadystatechange property. This property is an event handler which is triggered each time the state of the request changes. The states run from 0 (uninitialized) to 4 (complete). By having the function xmlhttpChange() check for the state changing, we can tell when the process is complete and continue only if it has been successful.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login