ajax发送post请求

function Auth () {
    var self = this;
    self.username = $('input[name="username"]').val();
    self.password = $('input[name="password"]').val();
}

Auth.prototype.getInfo = function () {
    self = this;
    $.ajax({
        type: "POST",
        url: '/',
        data:{
            'username': self.username,
            'password': self.password
        },
        success: function (result) {
            console.log(result)
        },
        error: function (result) {
            console.log(result)
        }
    })
};
Auth.prototype.btnClick = function () {
    var self = this;
    $('.btn').click(function () {
        self.getInfo()
    })
};

Auth.prototype.run = function () {
    var self = this;
    self.btnClick()

};

$(function () {
    var auth = new Auth();
    auth.run()
});
原文地址:https://www.cnblogs.com/fengzi7314/p/13602301.html