Page 1 of 1

My javascript code dont work in IE but work in others

Posted: Thu Oct 08, 2009 6:18 am
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

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

Posted: Thu Oct 08, 2009 3:59 pm
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.

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

Posted: Fri Oct 09, 2009 12:28 am
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.