Ajax调用有时工作,有时工作和刷新,有时刷新和失败....


Ajax Call Sometimes Works, Sometime works and refreshes, Sometimes refreshes and fails …?

目前我得到了这个代码:

function post_positive(id) {
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
  } else {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      document.getElementById("post"+id).innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","post_review.php?id="+id+"&type=positive",true);
  xmlhttp.send();
  return false; 
} 

对于我的ajax调用,我只是函数post_positive()。有时显示结果,有时显示页面刷新,有时不显示。

您使用jQuery ajax()方法ajax很容易理解和正常工作

函数post_positive(id){
美元。ajax ({
,,,,,,,,,类型:"得到",
,,,,,,,,,, url:"post_review.php",
,,,,,,,,,,数据:{"id":id,"类型":"正面"},
,,,,,,,,,,成功:函数(结果){
,,,,,,,,,,,,,,,,,,,,,("#职位"+ id)美元。text(结果);

,,,,,,,,,,,,,,,,,,,,,,}

,,,,,,,,,,,});
}