Ajax transmits parameters to XMLHttpReq. onreadystatechange

Source: Internet
Author: User

Ajax transmits parameters to XMLHttpReq. onreadystatechange

Pass:
Xmlhttp. onreadystatechange = function () {xx (123 )};
Or xmlhttp. onreadystatechange = new Function ("xx (123.
Copy codeThe Code is as follows:
Ajax transmits parameters to XMLHttpReq. onreadystatechange

Pass:
Xmlhttp. onreadystatechange = function () {xx (123 )};
Or
Xmlhttp. onreadystatechange = new Function ("xx (123 )");
You can.
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 codeThe Code is as follows:
<Html>
<Head>
<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); // refresh once per second
// --> </Mce: script>

</Head>
<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>
</Html>

Case 2:
Copy codeThe Code is as follows:
<Html>
<Head>
<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); // refresh once per second
// --> </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>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.