簡體   English   中英

Ajax POST永不發送?

[英]Ajax POST never gets sent?

由於某種原因,我的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>

您是否在使用某些外部Ajax類,至少在純JavaScript中不存在ajaxRequest()對象。 嘗試替代這條線

var mypostrequest = new ajaxRequest();

通過這樣:

var mypostrequest=new XMLHttpRequest();

然后甚至用

updateContentNow("","");

至少發出POST請求,就像使用Firebug可以輕松看到的那樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM