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;
}});
ajax操作登录