<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Ajax-only example: Reading data </title>
</Head>
<Body>
<SCRIPT type = "text/JavaScript">
Function ajaxcall ()
{
VaR XMLHTTP;
Try {// Firefox, opera 8.0 +, Safari
XMLHTTP = new XMLHttpRequest (); // instantiate the XMLHTTPRequest object
}
Catch (E)
{
// Internet Explorer 5 +
Try {
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
}
Catch (E)
{
Try
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Catch (E)
{
Alert ("the browser does not support Ajax! ");
Return false;
}
}
}
// Bind a data processing function.
XMLHTTP. onreadystatechange = function ()
{
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Document. getelementbyid ('txtresresult'). innerhtml = Document. getelementbyid ('txtusername'). Value + XMLHTTP. responsetext;
} Else
{
Alert ('request error .');
// There was a problem with the request,
// For example the response may be a 404 (not found)
// Or 500 (internal server error) Response codes
}
}
}
XMLHTTP. Open ("get", "data.txt", true); // asynchronous request data
XMLHTTP. Send (null );
}
</SCRIPT>
<Form style = "text-align: Left">
Name: <input type = "text" id = "txtusername" style = "width: 400px;"/>
<Br/>
Test: <input type = "button" id = "BTN" value = "test" onclick = "ajaxcall ();" style = "width: 400px;"/>
<Br/>
Result: <textarea id = "txtresult" style = "width: 400px;"> </textarea>
</Form>
</Body>
</Html>