<?xml version= "1.0" encoding= "gb2312"?>
<name> Welcome to Www.111cn.net. The development of this site can not be separated from your support. Thank you! </name>
Ajax files
<title> simple ajax effect </title>
<body>
We prepare an empty div. Fill in the returned data!
<div id= "str" style= "border:1px solid;" ></div>
<script language= "javascript tutorial"
var _xmlhttp//xmlhttprequest The global variable for image
// Create XMLHttpRequest in IE, apply to all versions of ie5.0 above
var msxmlhttp = new Array ("msxml2.xmlhttp.5.0",
"msxml2.xmlhttp.4.0";
msxml2.xmlhttp.3.0,
"Msxml2.xmlhttp",
"Microsoft.XMLHTTP");
for (Var i=0; i<msxmlhttp.length; i+ +) {
Try
{
_xmlhttp=new ActiveXObject (Msxmlhttp[i]);
}
catch (E)
{
_xmlhttp=null;
}
}//loops to create a XMLHTTP based on IE browser. End
///If non-IE browsers, create XMLHttpRequest
if (!_xmlhttp && typeof) based on browsers such as Firefox XMLHttpRequest!= "undefined")
{
_xmlhttp=new xmlhttprequest ();
}
/* The above code succeeded in creating a xmlhttprequest image. Applies to all modern browsers
below we begin to specify the server-side page to request and the way it is requested */
/* Start to specify server-side Web pages and send requests */
/* Define the server-side pages to be requested, in order to be straightforward, here I use an XML file. Because he does not
include any of the server-side program languages. Of course, you can use the ASP tutorials,. net,php tutorials and other documents. You need to be prompted: the most positive of the
System Ajax technology, are using XML as a data transmission format. You can use various server-side programs to generate XML format
*/
var url = "Back.xml"
_xmlhttp.open ("Get", url,true);//tested XML file can only be requested in get mode. But using the XML of the program output can use post
//The following is very important suggestion Read onReadyStateChange attribute detailed explanation
_xmlhttp.onreadystatechange = function () {
If (_xmlhttp.readystate==4) {
if (_xmlhttp.status==200) {
var xmldata=_xmlhttp.responsexml;
var my_name = Xmldata.getelementsbytagname ( "Name") [0].firstchild.nodevalue;
document.getElementById ("str"). innerHTML = My_name;
}
}
}
_xmlhttp.send (null);
</script>
All code for this instance is complete. After running the instance, you will see that the div above will have content displayed.
</body>