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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示