Compatibility of Ajax in different browsers (Asp.net, ie, Firefox)

Source: Internet
Author: User

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

 

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.