原始的JavaScript创建
代码
1 //global variable.
2 var xmlHttp;
3 //Create an XMLHttpRequest.
4 //Usage: This function is for create an XMLHttp Object. the object is for invoking the other page asynchronous
5 function createXMLHttp() {
6 var aVersions = [ "MSXML2.XMLHttp.5.0",
7 "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
8 "MSXML2.XMLHttp","Microsoft.XMLHttp"
9 ];
10 //if IE, it will return an XMLHttpRequest here.
11 for (var i = 0; i < aVersions.length; i++) {
12 try {
13 var oXmlHttp = new ActiveXObject(aVersions[i]);
14 return oXmlHttp;
15 } catch (oError) {
16 //if FireFox, it will return an XMLHttpRequest here.
17 if(window.XMLHttpRequest) {
18 return new XMLHttpRequest();
19 }else{
20 return null;
21 }
22 }
23 }
24 return null;
25 }
26 //Ajax will be initiated here.
27 function ajaxCreate(){
28 //Get an XMLHttpRequest from createXMLHttp.
29 xmlHttp = createXMLHttp();
30 //If cannot get an XMLHttpRequest, do the place order by the old version.
31 if(!xmlHttp){
32 window.location = "www.hondapartsnow.com";
33 return;
34 }
35 //when the state of the process is changed, do the following;
36 xmlHttp.onreadystatechange = disposeGetDemoOneSource;
37
38 //Do GET.
39 //this is for get the calculate page to invoke yourpay.
40 xmlHttp.open("GET", "Ajax.txt", true);
41 xmlHttp.send(null);
42 }
43
44 //this function will be invoked by the onreadystatechage.
45 function disposeGetDemoOneSource(){
46 //if the readyState is 4, mean the page has responed.
47 if(xmlHttp.readyState == 4){
48 //if the status is 200, mean it is ready for read the response.
49 if(xmlHttp.status == 200){
50 var responseText = xmlHttp.responseText;
51 //if we cannot get the reply from the server, show message to the customer. and redirect the URL to Listshoppingcart.aspx
52 //actually, if you cannot get the reply from the server, usally you cannot get ListShoppingCart.aspx also.
53 var oDiv = document.getElementById("Div1");
54 oDiv.innerHtml = responseText;
55 }else{
56 alert("New work problem occured, please check out the order again!");
57 }
58 }
59
60 }
2 var xmlHttp;
3 //Create an XMLHttpRequest.
4 //Usage: This function is for create an XMLHttp Object. the object is for invoking the other page asynchronous
5 function createXMLHttp() {
6 var aVersions = [ "MSXML2.XMLHttp.5.0",
7 "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
8 "MSXML2.XMLHttp","Microsoft.XMLHttp"
9 ];
10 //if IE, it will return an XMLHttpRequest here.
11 for (var i = 0; i < aVersions.length; i++) {
12 try {
13 var oXmlHttp = new ActiveXObject(aVersions[i]);
14 return oXmlHttp;
15 } catch (oError) {
16 //if FireFox, it will return an XMLHttpRequest here.
17 if(window.XMLHttpRequest) {
18 return new XMLHttpRequest();
19 }else{
20 return null;
21 }
22 }
23 }
24 return null;
25 }
26 //Ajax will be initiated here.
27 function ajaxCreate(){
28 //Get an XMLHttpRequest from createXMLHttp.
29 xmlHttp = createXMLHttp();
30 //If cannot get an XMLHttpRequest, do the place order by the old version.
31 if(!xmlHttp){
32 window.location = "www.hondapartsnow.com";
33 return;
34 }
35 //when the state of the process is changed, do the following;
36 xmlHttp.onreadystatechange = disposeGetDemoOneSource;
37
38 //Do GET.
39 //this is for get the calculate page to invoke yourpay.
40 xmlHttp.open("GET", "Ajax.txt", true);
41 xmlHttp.send(null);
42 }
43
44 //this function will be invoked by the onreadystatechage.
45 function disposeGetDemoOneSource(){
46 //if the readyState is 4, mean the page has responed.
47 if(xmlHttp.readyState == 4){
48 //if the status is 200, mean it is ready for read the response.
49 if(xmlHttp.status == 200){
50 var responseText = xmlHttp.responseText;
51 //if we cannot get the reply from the server, show message to the customer. and redirect the URL to Listshoppingcart.aspx
52 //actually, if you cannot get the reply from the server, usally you cannot get ListShoppingCart.aspx also.
53 var oDiv = document.getElementById("Div1");
54 oDiv.innerHtml = responseText;
55 }else{
56 alert("New work problem occured, please check out the order again!");
57 }
58 }
59
60 }
-------------------------------------------------
!!!作者:木由水 http://www.cnblogs.com/muyoushui