Ajax|xml
1<%@ Page language= "C #" codebehind= "$FILENAME $.cs" autoeventwireup= "false" inherits= "$INHERITS $"%>
2<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
3
45 6 <title>Ajax_exam1</title>
7 <meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
8 <meta name= "Code_language" content= "C #" >
9 <meta Name=vs_defaultclientscript content= "JavaScript" >
<meta name=vs_targetschema content= "http://schemas.microsoft.com/intellisense/ie5" >
One <meta http-equiv= "Content-type" content= "text/html charset=big5"/>
<script language=javascript>
13
VAR Ajax;
function Createajax ()
16 {
The If window. ActiveXObject)
18 {
Try
20 {
Return to new ActiveXObject ("Msxml2.xmlhttp");
22}
catch (E)
24 {
Try
26 {
Return to new ActiveXObject ("Microsoft.XMLHTTP");
28}
catch (E2)
30 {
return null;
32}
33}
34}
or else if window. XMLHttpRequest)
36 {
Panax Notoginseng return new XMLHttpRequest ();
38}
Or else
40 {
return null;
42}
43}
44
Onrcvdata function ()
46 {
if (ajax.readystate = 4)
48 {
if (Ajax.status = 200)
50 {
Wuyi var content = document.getElementById (' content ');
content.innerhtml = Ajax.responsetext;
53}
Or else
55 {
Alert (' Error from server! ');
57}
58}
59}
60
The function ajaxsendrequest (URL)
62 {
The Ajax = Createajax ();
if (!ajax)
65 {
Alert (' Explorer is Unsupport! ');
return 0;
68}
69
Ajax.onreadystatechange = Onrcvdata;
Ajax.open ("Get", url,true);
Ajax.send ("");
73}
74
75
</script>
<body ms_positioning= "GridLayout" >
79
<div id= "Content" ></div>
Bayi <br>
<input type= "button" value= "Search" >
83
</body>
8586
Please look at a simple example above, through which we can initially recognize the working mode of the AJAX structure! This example contains only a div tag, which is used to display the final result and a "search" button. The entire process is as follows:
The spirit of Ajax is not synchronized, so when the Ajax is out of the game, it does not wait for the server to respond, It is necessary to specify a specific image to let XMLHttpRequest notify JavaScript when receiving the response from the server. The onreadystatechange of this responsible notice.
Http://robin0925.cnblogs.com/archive/2006/06/14/425811.html