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 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同