代码之家  ›  专栏  ›  技术社区  ›  Dranna

未发送xmlhttpRequest

  •  0
  • Dranna  · 技术社区  · 6 年前

    我们是三个与Django合作开发Web应用程序项目的开发人员。

    某些通信客户端服务器使用API。一个特定的请求没有在开发人员的一台计算机上发送。我们使用相同的浏览器(火狐Quantum 64.0(64位))、相同的操作系统(Ubuntu 18.04)。

    下面是JS代码段:

    function requestHandler(url){
        let xhttp = new XMLHttpRequest();
        xhttp.open('POST', url, true);
        xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhttp.setRequestHeader('X-CSRFToken', getCookie('csrftoken'));
    
        xhttp.onreadystatechange = function(){
            if (this.readyState == 4 && this.status == 200) {
                drawLogTable();
            }
            else if (this.readyState == 4){
                console.log(this);
                new PNotify({
                    title: 'Échec!',
                    text: "Opération impossible: " + this.statusText,
                    type: 'error'
                });
            }
        }
        xhttp.send();
    }
    

    注意 url '../../api/log?action=accept&id=1'

    在所有工作的计算机和浏览器上,请求发布并执行404,因为服务器端还没有实现。在非工作的计算机上,Chromium可以工作,但在Firefox下,请求甚至没有被发送(服务器日志是空的),请求对象是完全空的(没有状态,没有文本)。

    我们还有其他同一类型的Ajax请求工作正常。

    1 回复  |  直到 6 年前
        1
  •  1
  •   doğukan    6 年前

    你能试试这个吗?

     xhttp.onload = function(){
            if (this.status == 200) {
                drawLogTable();
    }