Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2010, 06:33 AM   PM User | #1
lovekhan12345
New to the CF scene

 
Join Date: Dec 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
lovekhan12345 is an unknown quantity at this point
my script is not running on fire fox

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
lovekhan12345 is offline   Reply With Quote
Old 12-01-2010, 11:27 AM   PM User | #2
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Only IE supports ActiveX objects.

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

Code:
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:

Code:
<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>
Spudhead is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:21 PM.


Advertisement
Log in to turn off these ads.