weixin_33736649 2019-01-20 03:34 采纳率: 0%
浏览 49

Javascript Ajax移除方法

I am studying basic html, and now working on basic login/logout/create user/delete user (only when logged in as admin) stuff.

I have used PUT to update user password, POST to create user account, and DELETE to logout.

Now I want to delete user account when logged in as admin, but I have no idea how.

This is my third time asking this question here and I know my question is terrible. Hopefully my code will help you understand.

button.addEventListener("click",login);
    function login(){
        if(checkInput(username)==false||checkInput(password)==false){
            alert("bad input");
            return;
        }
        var params= "Name="+username.value+"&"+"password="+password.value;  
        var ajax = new XMLHttpRequest();
        ajax.responseType = "json";
        ajax.addEventListener("load",function(){
            console.log(this.response);

            messageSpan.innerHTML=this.response[0].message;

            if(this.response[0].status==true){
                button.style.display="none";

                logoutButton.style.display="inline";
                createButton.style.display="none";
                updateButton.style.display="inline"
            }

            if(username.value=="admin"){
                deleteButton.style.display="inline";
            }

        });

        ajax.open("POST","//cse.taylor.edu/~cos143/sessions.php");
        ajax.setRequestHeader("Content-type",
        "application/x-www-form-urlencoded");
        ajax.send(params);
    }


logoutButton.addEventListener("click",logout)
    function logout(){
        var ajax = new XMLHttpRequest();
        ajax.responseType = "json";
        ajax.addEventListener("load",function(){
            console.log(this.response[0]);

            messageSpan.innerHTML=this.response[0].message;
            if(this.response[0].status==true){
                button.style.display="inline";
                logoutButton.style.display="none";
                updateButton.style.display="none"
                createButton.style.display="inline";

            }

            deleteButton.style.display="none";

        });
        ajax.open("DELETE","//cse.taylor.edu/~cos143/sessions.php");
        ajax.send();    
    }

so these two are my eventlistener for login button and logout button. You will notice only ajax.open("~~~ has changed. I am going to do the same thing for delete user button, but I have no idea what I should write there!

I have tried remove, but console says unacceptable request type! plz help!

  • 写回答

1条回答 默认 最新

  • weixin_33739523 2019-01-20 04:07
    关注

    The problem may be on the server side. The server specifies which request types it will accept, and it sounds like maybe DELETE has not been set as one of those allowed types on your server.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog