如何通过页面输入账号密码提交给后端

2020-09-04 14:25发布

问题:

data : JSON.stringify({
                    "username":"zhangmou",
                    "password":"a12345678"
                    // username:$("name").val(),
                    // password:$("psw").val()
                }),

这段代码应该怎么改?

回答1:

$(document).ready(function () {
            $(".button").on("click",function(){
                    $.ajax({
                    type: "post",
                    url: "路由",
                    data : JSON.stringify({
                        // "username":"zhangmou",
                        // "password":"a12345678"
                        username:$("#name").val(),
                        password:$("#psw").val()
                    }),
                    // dataType: "dataType",
                    success: function (res) {
                        console.log(res)
                    }
                });
            })
        });


回答2:

你这不是都有了?

回答3:

data : {
  "username":"zhangmou",
  "password":"a12345678"
  // username:$("name").val(),
  // password:$("psw").val()
},

不用 JSON.stringify