...

View Full Version : my script is not running on fire fox



lovekhan12345
12-01-2010, 06:33 AM
Hi

i am using Php with ajax i found some problem in my scrip ,my site is running only IE but not in fire fox

my .js file

var xmlhttp=false;
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{

try

{

xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}catch(E)

{
xmlHTTP=false;

}
}





function request (page,objDiv)

{

var serverPage =page + "?time=" + new Date().getTime();
var obj= document.getElementById(objDiv);

obj.innerHTML="<img src=images/blu.gif width=16 height=16 id=loading align=center><br><font size=1 face=Verdana, Arial, Helvetica, sans-serif>Performing Specified Action...</font>";

xmlhttp.open("GET",serverPage);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readystate== 4 && xmlhttp.status== 200)
{
obj.innerHTML=xmlhttp.responseText;


}

}


xmlhttp.send(null);

}



what can i add then my script is running

Spudhead
12-01-2010, 11:27 AM
Only IE supports ActiveX objects.

You could use a wrapper function to return an XMLHTTP object:


function createXMLHttpRequest() {
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
alert("XMLHttpRequest not supported");
return null;
}
var xhReq = createXMLHttpRequest();


Why bother reinventing the wheel though? Let a framework do all the heavy lifting:



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
function request (page, objDiv){
var timestamp = new Date().getTime();
$(objDiv).html('<img src="images/blu.gif" width="16" height="16" id="loading" align="center"><br><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Performing Specified Action...</font>');
$.get(page, {'time' : timestamp}, function(response){
$(objDiv).html(response);
});
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum