My javascript code dont work in IE but work in others

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

My javascript code dont work in IE but work in others

Post by waseem83 »

Can any body tell me what should i do in my code it works fine in firefox and other browsers but not in IE.


function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

If any body tell me how should i initialize ActiveXobject which should work in all IE versions.

Thanks in advance
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: My javascript code dont work in IE but work in others

Post by kaszu »

If I remember correctly ActiveX name is case sensitive and I think "Msxml2.XMLHTTP" should be "MSXML2.XMLHTTP".

From jQuery source:

Code: Select all

function xhr() {
    return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
Please use

Code: Select all

tags in your next post.
waseem83
Forum Commoner
Posts: 54
Joined: Tue Jun 23, 2009 3:51 am
Contact:

Re: My javascript code dont work in IE but work in others

Post by waseem83 »

Thank you sir to send me above code i write it in capital letters but it still isnt working.

Actually i want to get server time and pass it to js function of new date(servertime), but there is no method of getting server time in java script it only exists in PHP. If any body knows any method of javascript which can get server time without involving PHP.

Thanks.
Post Reply