ajax操作登入

來源:互聯網
上載者:User

標籤:os   io   檔案   for   ar   cti   div   html   

js檔案中的內容(ajax.operate.js)

 

;
(function ($, window) {
var _ajaxOperate = window.ajaxOperate || {};

_ajaxOperate.callback = false;

_ajaxOperate.defaultOpts = {
callback:false,
clearCallback:false,
formParams:{}
};

var _ajaxLoginShow = function (opts) {
opts = $.extend(this.defaultOpts,opts);
if (opts.clearCallback) this.callback = false;
if (opts.callback) this.callback = opts.callback;
var url = "/ajax_quick_login.html";
$(‘#ajaxLoginFormWrapper .accbtn‘).removeClass("onclick");
$(‘#ajaxLoginFormWrapper .accbtn‘).removeAttr("disabled");
$.get(url,opts.formParams, function (data) {
$(‘#ajaxLoginFormWrapper‘).remove();
$("body").append(data);
});
};
_ajaxOperate.quickLogin = _ajaxLoginShow;

var _ajaxLoginHandle = function ($form) {
var self = this,
url = ‘/doajaxlogin.html‘;
$(‘#ajaxLoginFormWrapper .accbtn‘).addClass("onclick");
$(‘#ajaxLoginFormWrapper .accbtn‘).attr("disabled", "disabled");
$.post(url, $form.serialize(), function (data) {
if (data.status != 1) {
$(‘#ajaxLoginFormWrapper‘).addClass(‘err‘).find(‘div.errorBox‘).html(data.message).show(300);
$(‘#ajaxLoginFormWrapper .accbtn‘).removeClass("onclick").removeAttr("disabled");
} else {
$(‘#ajaxLoginFormWrapper‘).remove();
$(‘.step3Tips‘).size() > 0 && $(‘.step3Tips‘).hide();
self.callback != false && self.callback.call(self, data);
}
}, ‘json‘);
};
_ajaxOperate.quickLoginHandle = _ajaxLoginHandle;

var _ajaxRegShow = function (opts) {
opts = $.extend(this.defaultOpts,opts);
if (opts.clearCallback) this.callback = false;
if (opts.callback) this.callback = opts.callback;
var url = "/ajax_quick_reg.html";
$(‘#ajaxLoginFormWrapper .accbtn‘).removeClass("onclick");
$(‘#ajaxLoginFormWrapper .accbtn‘).removeAttr("disabled");
$.get(url, function (data) {
$(‘#ajaxLoginFormWrapper‘).remove();
$("body").append(data);
});
};
_ajaxOperate.quickReg = _ajaxRegShow;

var _ajaxRegHandle = function ($form) {
var self = this,
url = ‘/doajaxregister.html‘;
$(‘#ajaxLoginFormWrapper .leftForm ul li em.tips‘).hide();
$(‘#ajaxLoginFormWrapper .accbtn‘).addClass("onclick").attr("disabled", "disabled");
$.post(url, $form.serialize(), function (data) {
if (data.status != 1) {
$(‘#ajaxLoginFormWrapper .leftForm ul li em.‘+data.field).html(data.message).show();
//$(‘#ajaxLoginFormWrapper‘).addClass(‘err‘).find(‘div.errorBox‘).html(data.message).show(300);
$(‘#ajaxLoginFormWrapper .accbtn‘).removeClass("onclick").removeAttr("disabled");
} else {
$(‘#ajaxLoginFormWrapper‘).remove();
self.callback != false && self.callback.call(self, data);
}
}, ‘json‘);
};
_ajaxOperate.quickRegHandle = _ajaxRegHandle;

window.ajaxOperate = _ajaxOperate;

})(jQuery, window);
$(document).keypress(function (e) {
var key = e.which;
if (key == 13) {
if ($(‘#ajaxLoginFormWrapper‘).size() > 0) {
$(‘#ajaxLoginFormWrapper‘).find(‘input.accbtn‘).trigger(‘click‘);
return false;
}
}
});

 裡面會展示登入html

然後點擊登入操作(賦值回呼函數)

ajaxOperate.callback != false && ajaxOperate.callback.call(ajaxOperate, data);

 

操作中ajax操作後的回調方法書寫

ajaxOperate.quickLogin({callback: function (dataHeader) {
doPost($this, url, postData, extralOptions);
return false;
}});

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.