views:

468

answers:

5

But it works in firefox.

This is my javascript:

star.updateRating=function(v, listid) { 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
 alert("Your browser does not support AJAX!");
 return;
}  
var randomnbr = randomID(12); 
var cacheid = randomnbr+"_"+listid;     
var url="http://mywebsiteurl.com/includes/functions_rating.php";     
 url=url+"?action=ratelist";        
 url=url+"&listid="+listid;      
 url=url+"&rating="+v;  
 url=url+"&cid="+cacheid;    
// disable the container 
$('starMsg').innerHTML=' - Thanks for rating!';
$('star').setAttribute('onmousemove','');
$('star').setAttribute('onmousedown','');

xmlHttp.open("POST",url,true);
xmlHttp.send(null);

}

My php file begins with : header ("content-type: text/xml");

The code will run all the way through (an alert(1); will execute at the end of the js). However, the php does not update the database when the script is called from ie.

Any ideas?

A: 

How do you create your XMLHTTPRequest object? Remember that it needs to be done differently in IE than in Firefox.

Marius
+1  A: 

Use the following to get the Object correctly in IE as well as FF:

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;
}

And use the function:

xmlhttp=GetXmlHttpObject();

EDIT: On second thoughts, you may be getting the object correctly (although you have not mentioned your GetXmlHttpObject() function - which is why I am leaving my above answer around.

But you are calling xmlhttp.send(null) while the method you mention is POST. Are you sending an empty request to the server? If not, then either add the variables to be sent via POST in .send() or change the method to GET and put your variables in the url.

Crimson
+2  A: 

Why don't you use something like jquery to hide these browser-specific differences?

jeroenh
+1 for mentioning jquery
Mohamed
A: 

Shoot, it was a problem in my php file. I was using a different user in ie versus in ff so I didn't catch it at first. Actually, there were two problems involved and one of them was solved by changing back to GET. (I changed to POST originally because it was offered as a solution to ie ajax problems in other questions).

A: 
xmlHttp.open("POST",url,true);
xmlHttp.send(null);

send(null) is questionable, this might be what's wrong.

You can say send('') to send an empty body, or omit the parameter completely (send()), but including a null parameter is not specified by the XMLHttpRequest interface.

For a POST request it would be usual to send the form-encoded (a=b&x=y) string as the request body, rather than including it in the query string.

(Because adding a rating is a state-changing action, you definitely should be using POST and not GET.)

bobince