Ajax POST永远不会被发送?

时间:2014-02-02 23:21:33

标签: javascript php jquery ajax post

我的ajax POST出现问题因为某些原因从未制作过POST!不能为我的生活工作吗?

是的,所以我在firefox中使用网络调试工具来检查POST请求,但POST请求永远不会被发出..

这个函数肯定也被调用了,因为我已经在运行的函数的开头添加了一个警告alert("start")

AJAX

<script>
function updateContentNow(pid2, status2) {
    var mypostrequest = new ajaxRequest();
    mypostrequest.onreadystatechange = function() {
        if (mypostrequest.readyState == 4) {
            if (mypostrequest.status == 200 || window.location.href.indexOf("http") == -1) {
                document.getElementById("livestats").innerHTML = mypostrequest.responseText;
            } else {
                alert("An error has occured making the request");
            }
        }
    }
    var parameters = "cid=clientid&pid=6&statusinfo=approve";
    mypostrequest.open("POST", "http://mydomain.com.au/content-approval/ajax.php", true);
    mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    mypostrequest.send(parameters);
}
</script>

更新工作:谢谢你......

<script>
function updateContentNow(pid2,status2)
{
var mypostrequest=new XMLHttpRequest()
mypostrequest.onreadystatechange=function(){
 if (mypostrequest.readyState==4){
  if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
   document.getElementById("livestats").innerHTML=mypostrequest.responseText;
  }
  else{
   alert("An error has occured making the request");
  }
 }
}
var parameters="cid=<?=$clientID?>&pid="+pid2+"&statusinfo="+status2;
mypostrequest.open("POST", "http://mydomain.com.au/content-approval/ajax.php", true);
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
mypostrequest.send(parameters);
}
</script>

1 个答案:

答案 0 :(得分:1)

您使用的是一些外部Ajax类,至少在纯JavaScript中不存在ajaxRequest()对象。尝试替换此行

var mypostrequest = new ajaxRequest();

由此:

var mypostrequest=new XMLHttpRequest();

然后甚至用

调用你的方法
updateContentNow("","");

至少可以使用Firebug轻松查看POST请求。