user1104615
user1104615

Reputation: 21

ajax works on firefox and chrome but not on ie

I am making votes with ajax, each IP can vote once. It works, it won't add more than once to the database. Now I want immedently to show to the user that he voted so I use this code:

function vote(id)
{
    var xmlhttp;
     if (window.XMLHttpRequest)
       {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
       }
     else
       {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }

    xmlhttp.onreadystatechange=function()
       {
       if (xmlhttp.readyState==4 && xmlhttp.status==200)
         {

            if (xmlhttp.responseText == "true1")
                document.getElementById("b"+id).innerHTML = parseInt(document.getElementById("b"+id).innerHTML) + 1;
         }
       }

    xmlhttp.open("GET","vote.php?id="+id,true);
    xmlhttp.send();
}

In the vote.php page here is the code:

if (!(mysql_fetch_array(mysql_query("SELECT * FROM `votes` WHERE IP = '$IP'"))))
{
    echo "true1";
}
else
{
    echo "false0";
}

Works great with FireFox and chrome. Tried with firebug, I do get the "true1" or the "false0" but with IE it doesn't work, why?

Upvotes: 0

Views: 1213

Answers (1)

Tim Wickstrom
Tim Wickstrom

Reputation: 5701

Change your ajax request to a POST instead of GET IE is notorious for cach'ing request that are GET.

Dont forget to update your PHP variables to $_POST as well.

Once this is done the problem will go away.

Upvotes: 4

Related Questions