重温Ajax
1 <script type="text/javascript">
2
3 var xmlhttp;
4 var url = "ajax.aspx";
5
6 function createxmlttp() {
7
8 if (window.XMLHttpRequest) {
9 xmlhttp = new XMLHttpRequest();
10 }
11
12 if (window.ActiveXobject) {
13 try {
14
15 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
16 }
17 catch (e) {
18
19 try {
20 xmlhttp = new ActiveXObject("msxml2.XMLHTTP");
21 }
22 catch (e)
23 { }
24 }
25
26 }
27
28 }
29
30 function TestAjax() {
31 var obj = document.getElementById('txtcontent');
32 createxmlttp(); //创建xmlhttp
33
34 if (!xmlhttp) {
35 alert("xmlhttp创建失败.");
36 }
37 else {
38
39 xmlhttp.open("post", url, true);
40 xmlhttp.onreadystatechange = function() {
41
42 if (xmlhttp.readyState == 4) {
43
44 var msg = document.getElementById('msg');
45 msg.value = '数据正在加载。。';
46
47 if (xmlhttp.status == 200) {
48 //alert(xmlhttp.responseText); return false;
49 obj.innerHTML=xmlhttp.responseText;
50 }
51 }
52 }
53 }
54
55 xmlhttp.send("msg='sss'");
56
57 }
58
59
60 </script>
2
3 var xmlhttp;
4 var url = "ajax.aspx";
5
6 function createxmlttp() {
7
8 if (window.XMLHttpRequest) {
9 xmlhttp = new XMLHttpRequest();
10 }
11
12 if (window.ActiveXobject) {
13 try {
14
15 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
16 }
17 catch (e) {
18
19 try {
20 xmlhttp = new ActiveXObject("msxml2.XMLHTTP");
21 }
22 catch (e)
23 { }
24 }
25
26 }
27
28 }
29
30 function TestAjax() {
31 var obj = document.getElementById('txtcontent');
32 createxmlttp(); //创建xmlhttp
33
34 if (!xmlhttp) {
35 alert("xmlhttp创建失败.");
36 }
37 else {
38
39 xmlhttp.open("post", url, true);
40 xmlhttp.onreadystatechange = function() {
41
42 if (xmlhttp.readyState == 4) {
43
44 var msg = document.getElementById('msg');
45 msg.value = '数据正在加载。。';
46
47 if (xmlhttp.status == 200) {
48 //alert(xmlhttp.responseText); return false;
49 obj.innerHTML=xmlhttp.responseText;
50 }
51 }
52 }
53 }
54
55 xmlhttp.send("msg='sss'");
56
57 }
58
59
60 </script>
1 <input type="button" value="测试" onclick="TestAjax()" />
2 <label id="msg"></label>
3 <label id="txtcontent"></label>
2 <label id="msg"></label>
3 <label id="txtcontent"></label>
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 namespace TestUrl
9 {
10 public partial class ajax : System.Web.UI.Page
11 {
12 protected void Page_Load(object sender, EventArgs e)
13 {
14 Response.Write(DateTime.Now);
15 Response.Write(Request["msg"]);
16 Response.End();
17 }
18 }
19 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 namespace TestUrl
9 {
10 public partial class ajax : System.Web.UI.Page
11 {
12 protected void Page_Load(object sender, EventArgs e)
13 {
14 Response.Write(DateTime.Now);
15 Response.Write(Request["msg"]);
16 Response.End();
17 }
18 }
19 }