001.
<
div
id
=
"a"
></
div
>
002.
<
div
id
=
'b'
></
div
>
003.
<
input
type
=
"button"
onclick
=
"startXMLHttp();"
value
=
"普通GET"
/>
004.
<
div
id
=
"a1"
></
div
>
005.
<
div
id
=
'b1'
></
div
>
006.
<
input
type
=
"button"
onclick
=
"startXMLHttp1();"
value
=
"普通POST"
/>
007.
<
div
id
=
"c"
></
div
>
008.
<
div
id
=
"d"
></
div
>
009.
<
input
type
=
"button"
onclick
=
"prototypeSend();"
value
=
"prototype
GET"
/>
010.
<
div
id
=
"c1"
></
div
>
011.
<
div
id
=
"d1"
></
div
>
012.
<
input
type
=
"button"
onclick
=
"prototypeSend1();"
value
=
"prototype
POST"
/>
013.
014.
<
script
type
=
"text/javascript"
>
015.
var xmlHttp;
016.
function createXMLHttp()
017.
{
018.
if (window.XMLHttpRequest)
019.
{
020.
xmlHttp = new XMLHttpRequest();
021.
}
022.
else if (window.ActiveXObject)
023.
{
024.
try
025.
{
026.
xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
027.
}
028.
catch(e)
029.
{
030.
try
031.
{
032.
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
033.
}
034.
catch(e) {};
035.
}
036.
}
037.
}
038.
039.
function startXMLHttp()
040.
{
041.
createXMLHttp();
042.
var sendStr =
"name=博科&age=23&en=<>@+/ ://'f#a&mn=%rt";
043.
sendStr = encodeURI(sendStr);
044.
document.getElementById('a').innerHTML = sendStr;
045.
xmlHttp.onreadystatechange = doSomething;
046.
xmlHttp.open('GET','ajaxtest.php?'+sendStr,true);
047.
xmlHttp.send(null);
048.
}
049.
050.
function doSomething()
051.
{
052.
053.
if (xmlHttp.readyState == 4)
054.
{
055.
if (xmlHttp.status == 200)
056.
{
057.
document.getElementById('b').innerHTML =
xmlHttp.responseText;
058.
}
059.
}
060.
}
061.
062.
function startXMLHttp1()
063.
{
064.
createXMLHttp();
065.
var sendStr =
"name=博科&age=23&en=<>@+/ ://'f#a&mn=%rt";
066.
sendStr = encodeURI(sendStr);
067.
document.getElementById('a1').innerHTML = sendStr;
068.
xmlHttp.onreadystatechange = doSomething1;
069.
//xmlHttp.open('GET','ajaxtest.php?'+sendStr,true);
070.
//xmlHttp.send(null);
071.
xmlHttp.open('POST','ajaxtest.php',true);
072.
xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
073.
xmlHttp.send(sendStr);
074.
}
075.
076.
function doSomething1()
077.
{
078.
079.
if (xmlHttp.readyState == 4)
080.
{
081.
if (xmlHttp.status == 200)
082.
{
083.
document.getElementById('b1').innerHTML =
xmlHttp.responseText;
084.
}
085.
}
086.
}
087.
</
script
>
088.
089.
<
script
type
=
"text/javascript"
>
090.
function
prototypeSend()
091.
{
092.
var po = new Ajax.Request('ajaxtest.php',
093.
{
094.
method:'GET',
095.
parameters: "name=博科&age=23&en=<>@+/
://'f#a&mn=%rt",
096.
onSuccess: function(transport){
097.
document.getElementById('c').innerHTML =
po.parameters.name+po.parameters.age+po.parameters.en;
098.
document.getElementById('d').innerHTML =
transport.responseText;
099.
},
100.
onFailure: function(){ }
101.
});
102.
}
103.
function
prototypeSend1()
104.
{
105.
var po = new Ajax.Request('ajaxtest.php',
106.
{
107.
method:'POST',
108.
parameters: "name=博科&age=23&en=<>@+/
://'f#a&mn=%rt",
109.
onSuccess: function(transport){
110.
document.getElementById('c1').innerHTML =
po.parameters.name+po.parameters.age+po.parameters.en;
111.
document.getElementById('d1').innerHTML =
transport.responseText;
112.
},
113.
onFailure: function(){ }
114.
});
115.
}
116.
</
script
>