简体   繁体   中英

AJAX request only works once in IE

I have this issue, in FF it works great but in IE only works once... the html is

<form>
<input type="button" value="test" onclick="javascript:vote();"/>
</form>

the javascript

<script type="text/javascript">

function vote(){


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();


  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  }


xmlhttp.open("GET","../php/votes.php",true);
xmlhttp.send(null);

}

</script>

and the PHP code is only a update

<?php
$con = mysql_connect("localhost","mylog","mypass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('versus',$con);

mysql_query("update picture_vs set votes = votes + 1");


?>

any idea?

Modify the following line to...

xmlhttp.open( "GET", "../php/votes.php?random=" + Math.random(), true);

This will prevent IE from caching your request by URI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM