Jump to content

xmlhttp and firefox


igor21

Recommended Posts

hey!I have some script that works greate in IE but not works in Firefox.

function isExist(url,queries){     var xmlhttp;     try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }       catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }       catch (e) { try { xmlhttp = new XMLHttpRequest(); }       catch (e) { xmlhttp = false; }}}     xmlhttp.Open('POST',url,false);     xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");     xmlhttp.Send(queries);     var result=(xmlhttp.responseText);     return result; }

What's wrong?Thanks!

Link to comment
Share on other sites

try setting it like this

var xmlHttp;if(document.all){  //IE  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}else{  //FF,Opera,NN  xmlHttp = new XMLHttpRequest();}

Link to comment
Share on other sites

Does:

function isExist(url,queries){    var xmlHttp;    try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }      catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }      catch (e) { try { xmlHttp = new XMLHttpRequest(); }      catch (e) { xmlHttp = false; }}}    xmlHttp.open('POST',url,false);    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");    xmlHttp.send(queries);    var result=(xmlHttp.responseText);    return result; }

work?

Link to comment
Share on other sites

  • 5 months later...

By the way, let me suggest that the scripts should first check for XmlHttpRequest() and then use ActiveX if not available. The reason is that IE7 now has native support for this object and acts faster with it. This would also increase performance in FF and Opera, scince they as well as IE7 won't try check the second code once the first it true.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...