views:

53

answers:

4

I have created a Question of the week project in PHP and I have used AJAX to make things work in run time and MySQL as the database. My entire project works absolutely fine in Firefox and even in Google Chrome. But it does not works on Internet Explorer.

It does not makes the changes. eg. If I post using IE, it will not show the posted question in the response, even if I try to refresh. But if I refresh my project in Firefox, it shows me the question posted. To see the changes in IE, I actually have to close the IE and start all over again.

Can you please suggest what all should I do to get rid of this problem?

+3  A: 

For IE, you must use Active X

var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
Time Machine
+1  A: 

IE has a tendency to cache the AJAX responses. Try to add some randomness to your query so it looks as a "new" page is being requested each time there is an AJAX call.

mr-euro
A: 

for the ajax part see the other answers, as for the refresh part you might want to look at how to avoid client side cache in IE

Nuno Furtado
+1  A: 

If you're using AJAX to post the questions are you using your own custom Javascript or are you using a framework (like jQuery)? If you are writing your own javascript to handle everything, make sure you're getting the proper XmlHttpRequest from the browser (the code I use to get the right object is below). Also, you didn't state what version of IE you are using. If you are using IE8, you can use the developer tools (press F12 or Tools -> Developer Tools) to debug your javascript.

Code for getting XmlHttpObject:

function GetXmlHttpObject() {
  var xmlHttp = null;
  try {
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}
Joshua