7 Replies - 2611 Views - Last Post: 24 July 2009 - 12:52 PM

#1 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 08:21 AM

this is wierd, does anyone else have problems with ajax in anything other than FF as mine works perfectly in FF but not at all in IE or Safari, i havent tested any other browsers. how can i fix this easily without having to rechange all my code. i mean i use this function

but it obviously isnt working. because i dont get any errors

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


Is This A Good Question/Topic? 0
  • +

Replies To: firefox works, IE and Safari 4 dont

#2 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 96
  • Joined: 24-July 09

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 08:25 AM

there are two types of requests for IE you ca use.try this code
var request;
function createGETRequest() {
request=false;
  try {
	request = new XMLHttpRequest();
  } catch (trymicrosoft) {
	try {
	  request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
	  try {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (failed) {
		request = false;
	  }
	}
  }

  if (!request)
	alert("Error initializing XMLHttpRequest!");
}


This post has been edited by izrafel: 24 July 2009 - 08:26 AM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 08:26 AM

Well since it's the AJAX you're having an issue with, and not the PHP, I'm moving this to the Javascript forum :)
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3778
  • View blog
  • Posts: 13,687
  • Joined: 08-August 08

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 08:30 AM

Try inserting an alert to see if your problem really is with this code:
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  alert('The request is being returned!');
 return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

Was This Post Helpful? 0
  • +
  • -

#5 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 08:54 AM

no which means it must be to do with this code then

function submitenter(myfield,e)
{
var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   if(message.value != ""){
			var test = <?php echo $_SESSION['u2'];?>;
			sendMessage(message.value, test);	
			return false;		
		}		
		
	   }
	else
	   return true;
}



and also it is starting to play up a little but as underneath my text box it should echo added succesfully however sometimes it doesnt at all and sometimes it puts the chat log there instead of the success msg even though its a differant id, why is this ?
Was This Post Helpful? 0
  • +
  • -

#6 izrafel  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 96
  • Joined: 24-July 09

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 09:00 AM

1.where is the variable message defined?
2.if
 var test = <?php echo $_SESSION['u2'];?>;


should be string i believe it should be
 var test = '<?php echo $_SESSION['u2'];?>';


(but i am not sure i can't test now).
Was This Post Helpful? 0
  • +
  • -

#7 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 903
  • Joined: 08-August 08

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 12:41 PM

its from a text area with the id message so message.value gets its value.

the wierd thing is that i works in firefox but it doesnt even activate the ajax in ie or safari so it must be something to do with the onkey press bit
Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,566
  • Joined: 05-June 09

Re: firefox works, IE and Safari 4 dont

Posted 24 July 2009 - 12:52 PM

Try using the onsubmit event of the containing form..

To get an XMLHttpRequest object just use
var IE = /*@cc_on!@*/false;
var http = (IE?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest());


No need for that pointless function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1