Ajax compatibility issues in different browsers (Asp.net,ie,firefox)

Source: Internet
Author: User

Ajax compatibility issues in different browsers are troublesome, and I have encountered this problem in recent projects. And used a strange way to solve it, and now come out to discuss the discussion:

The following is the front-end code:

<script type= "Text/javascript" >
var xmlHttp;
var as;
var state = 0;
function MouseOver ()
{
var id = "<%=cvE_Mail.ClientID%>";

Getajax ();
if (as = = 0)
{
Alert ("Your WebBrowser don't support our service,choose IE7 or FireFox and try again!");
}
Else
{
At the time of the return, the state-setting event is different.
if (as = = 1)
{
Xmlhttp.onreadystatechange = Myresponsehandler;
}
Else
{
Xmlhttp.onload = Myresponsehandler;
Xmlhttp.onerror = Myresponsehandler;
}
In this case, when the open is chosen for GET, it is strange that Firefox's processing end will not receive the passed parameters
Here you can see that the last parameter is also different, and if not, then the returned responsetext is probably 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 is to create a different time
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>

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.