Ajax passes parameters to Xmlhttpreq.onreadystatechange
Pass:
xmlhttp.onreadystatechange= function () {XX (123)};
Or xmlhttp.onreadystatechange= the new Function ("XX (123)"); It's OK.
Copy Code code as follows:
Ajax passes parameters to Xmlhttpreq.onreadystatechange
Pass:
xmlhttp.onreadystatechange= function () {XX (123)};
Or
xmlhttp.onreadystatechange= new Function ("XX (123)");
It's OK.
M=document.getelementsbyname ("Text8");
V=m[i];
Xmlhttpreq.onreadystatechange=function () {proce (v)};
----------------------------------------------
function Proce (v)
{
if (xmlhttpreq.readystate==4)
{
if (xmlhttpreq.status==200)
{
var res=xmlhttpreq.responsexml.getelementsbytagname ("Content") [0].firstchild.data;
V.value=res;
}
Else
{
V.value= ' ... ';
}
}
}
An example of a small test:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>test ajax</title>
<mce:script language= "JavaScript" ><!--
function Getxmlhttprequest () {
var XMLHttpRequest;
Try
{
Xmlhttprequest=new XMLHttpRequest ();
}
catch (E)
{
Try
{
Xmlhttprequest=new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
Try
{
Xmlhttprequest=new activexobjec ("msxml2.xmlhttp");
}
catch (E)
{
throw new Error (' Unable to create XMLHttpRequest. ')
}
}
}
return XMLHttpRequest;
}
/*
function Test () {
var xhr = Getxmlhttprequest ();
var url= "Http://211.87.235.108:5000/sensor.xml";
Xhr.open ("get", url);
Xhr.send (NULL);
Xhr.onreadystatechange = function () {
if (4==xhr.readystate)
{
if (200==xhr.status) {
var xmldoc=xmlhttprequest.responsexml;
var Xmldoc=xhr.responsetext;
document.getElementById ("disp"). Innerhtml=xmldoc;
}
else {
alert (xhr.status);
}
}
};
Xhr.onstatechange = function () {
Handlexmlhttprequest (XHR);
};
}
*/
function Handlexmlhttprequest (XMLHttpRequest) {
if (4==xmlhttprequest.readystate)
{
if (200==xmlhttprequest.status) {
var xmldoc=xmlhttprequest.responsexml;
var Xmldoc=xmlhttprequest.responsetext;
document.getElementById ("disp"). Innerhtml=xmldoc;
}
else {
alert (xmlhttprequest.status);
}
}
}
function Doxmlhttprequest () {
var xhr = Getxmlhttprequest ();
var url= "Http://localhost:5000/sensor.xml";
Xhr.open ("get", url);
Xhr.send (NULL);
Xhr.onreadystatechange =function () {
Handlexmlhttprequest (XHR);
};
}
function Myrefresh () {
Window.location.reload ();
}
SetTimeout (' Myrefresh () ', 1000); Specify 1 seconds to refresh once
--></mce:script>
<mce:style><!--
body {font-size:12px;}
--></mce:style><style mce_bogus= "1" > Body {font-size:12px;} </style>
<body onload= "doxmlhttprequest ()" >
<div id= "disp" >
</div>
</body>
Use Case 2:
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> my Documents </title>
<mce:script language= "JavaScript" ><!--
function Getxmlhttprequest () {
var XMLHttpRequest;
Try
{
Xmlhttprequest=new XMLHttpRequest ();
}
catch (E)
{
Try
{
Xmlhttprequest=new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
Try
{
Xmlhttprequest=new activexobjec ("msxml2.xmlhttp");
}
catch (E)
{
throw new Error (' Unable to create XMLHttpRequest. ')
}
}
}
return XMLHttpRequest;
}
function Test () {
var xhr = Getxmlhttprequest ();
var url= "Http://211.87.235.108:5000/sensor.xml";
Xhr.open ("get", url);
Xhr.send (NULL);
Xhr.onreadystatechange = function () {
if (4==xhr.readystate)
{
if (200==xhr.status) {
var xmldoc=xmlhttprequest.responsexml;
var Xmldoc=xhr.responsetext;
document.getElementById ("disp"). Innerhtml=xmldoc;
}
else {
alert (xhr.status);
}
}
};
}
/*
function Handlexmlhttprequest (XMLHttpRequest) {
Alert (XMLHttpRequest + 2);
if (4==xmlhttprequest.readystate)
{
if (200==xmlhttprequest.status) {
var xmldoc=xmlhttprequest.responsexml;
var Xmldoc=xmlhttprequest.responsetext;
document.getElementById ("disp"). Innerhtml=xmldoc;
}
else {
alert (xmlhttprequest.status);
}
}
}
function Doxmlhttprequest () {
var xhr = Getxmlhttprequest ();
var url= "Http://211.87.235.108:5000/sensor.xml";
Xhr.open ("get", url);
Xhr.send (NULL);
Xhr.onreadystatechange = Handlexmlhttprequest ();
}
*/
function Myrefresh () {
Window.location.reload ();
}
SetTimeout (' Myrefresh () ', 1000); Specify 1 seconds to refresh once
--></mce:script>
</HEAD>
<mce:style><!--
body {font-size:12px;}
--></mce:style><style mce_bogus= "1" > Body {font-size:12px;} </style>
<body onload= "Test ()" >
<div id= "disp" >
</div>
</body>