Many people now understand Ajax technology, but when using it, the code is varied and difficult to understand and maintain. Now there are some Ajax frameworks that do well, such as the earlier xajax (under PHP) and jquery and DHTML. However, because the framework should consider universality and compatibility, it is complicated to implement stacked bedframe. For some of our small applications, they are very helpful and can be used to crack down on mosquitoes.
In fact, Ajax has become a mysterious thing for everyone-look at the Ajax-related books in the reading shop.
The following code constructs two functions (not intended to be implemented using classes) by using the get method to implement Ajax requests, which can satisfy daily simple applications, it almost embodies all the essence of Ajax. When used, you can call the function by giving several parameters.
Function getajax (httpurl, requests, Div)
{
If (typeof (httpurl, requests, Div) = 'undefined ')
{
Return false;
}
VaR url = httpurl + requests;
VaR show = Document. getelementbyid (DIV );
VaR Ajax = initajax ();
Ajax. Open ("get", URL, true );
Ajax. onreadystatechange = function (){
If (Ajax. readystate = 4 & Ajax. Status = 200 ){
Show. innerhtml = Ajax. responsetext;
}
}
Ajax. Send (null );
}
Function initajax ()
{
VaR Ajax = false;
Try {
Ajax = new activexobject ("msxml2.xmlhttp ");
} Catch (e ){
Try {
Ajax = new activexobject ("Microsoft. XMLHTTP ");
} Catch (e ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = 'Undefined '){
Ajax = new XMLHttpRequest ();
}
Return Ajax;
}
Zhang Qing (mesh)
From mesh horizon: http://blog.why100000.com
Why 100,000 computer learning networks: http://www.why100000.com