Ajax compatibility problems in different browsers are troublesome. I encountered this problem in my recent project. I used a strange method to solve it. Now I will discuss it with you:
Below is the front-endCode:
<SCRIPT type = "text/JavaScript">
VaR XMLHTTP;
VaR;
VaR state = 0;
Function Mouseover ()
{
VaR id = "<% = cve_mail.clientid %> ";
Getajax ();
If (as = 0)
{
Alert ("Your webbrowser do not support our service, choose IE7 or Firefox and try again! ");
}
Else
{
// The bonding event is also different during the return.
If (as = 1)
{
XMLHTTP. onreadystatechange = myresponsehandler;
}
Else
{
XMLHTTP. onload = myresponsehandler;
XMLHTTP. onerror = myresponsehandler;
}
// If you select get as the open method, it is strange that the Firefox processing end cannot receive the passed parameters.
// The last parameter is also different here. If this parameter is not set, the returned responsetext may be empty.
If (as = 1)
{
XMLHTTP. Open ("Post", "Ajax. ashx", true );
}
Else
{
XMLHTTP. Open ("Post", "Ajax. ashx", false );
}
XMLHTTP. Send (document. getelementbyid (ID). value );
}
};
Function getajax ()
{
// The first step is to create different
Try {
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
As = 1;
} Catch (e ){
Try {
XMLHTTP = new activexobject ("msxml2.xmlhttp ");
As = 1;
} Catch (e ){
Try {
XMLHTTP = new XMLHttpRequest ();
As = 2;
} Catch (e ){
XMLHTTP = NULL;
As = 0;
}
}
}
}
Function myresponsehandler ()
{
VaR id = "<% = hidebutton. clientid %> ";
If (XMLHTTP. readystate = 4)
{
Document. getelementbyid (ID). value = XMLHTTP. responsetext;
}
};
</SCRIPT>
Backend code (Asp.net ):
Public class cajax: ihttphandler
{
Public void processrequest (httpcontext context)
{
// First read the value passed by the front end
Httprequest request = context. request;
System. Io. Stream S = request. inputstream;
Int COUNT = 0;
Byte [] buffer = new byte [1024];
Stringbuilder builder = new stringbuilder ();
While (COUNT = S. Read (buffer, 0, 1024)> 0)
{
Builder. append (encoding. utf8.getstring (buffer, 0, count ));
}
String request = builder. tostring (); // request is the passed parameter.
..................
// Result indicates the result to be returned.
Context. response. Write (result );
}
}
This solution I in Firefox, ie, roaming inside all tested no problem, if interested can send me a mail: zhaotiantang520@live.cn