ajax提交数据(代理函数)

ajax 提交


//1.判断是否为登陆用户
function isLogin(url,page) {
try{
var a=new MyAjax();
var u = <%=request.getContextPath()%>/LoginAction.do?action=unLogin;
var queryString="validateCode="+_$('uval').value+"&loginName="+_$('uname').value+"&password="+_$('upwd').value;
a.sendPostRequest(queryString,url,checkIsLogin.createDelegate(a));
}catch(e){

}
}
//处理action
public ActionForward unLogin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String[] userAry = (String[])request.getSession().getAttribute("userAry");
// System.out.println("session has be removed!");
PrintWriter out = null;
try {
out = response.getWriter();
} catch (java.io.IOException e) {}
if(userAry!=null){
out.print("{relust:'yes'}");
}else{
out.print("{result:'no'}");
}
return mapping.findForward(NOFORWARD);
}
//2.回调函数
function checkIsLogin(){
var xmlHttp=this.xmlHttp;
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var json=eval("("+xmlHttp.responseText+")");
if(json.result!='0000'){
alert(json.errorMessage);
return;
}
}else{
window.alert("ajax状态错误!");
}
}
}
//3.页面调用
<script type="text/javascript" src="<%=request.getContextPath() %>/js/ExtFunction.js"></script>
//4.代理对象
Ext = {};//Ext = {};
Ext.javapackage = function() {
var a = arguments, o = null, i, j, d, rt;
for (i = 0;i < a.length; ++i) {
d = a[i].split(".");
rt = d[0];
eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = '
+ rt + ';');
for (j = 1;j < d.length; ++j) {
o[d[j]] = o[d[j]] || {};
o = o[d[j]];
}
}
};

Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}
if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}
}
return o;
};

/*====================Array====================*/
Ext.apply(Array.prototype, {
indexOf : function(o){
for (var i = 0, len = this.length; i < len; i++){
if(this[i] == o) return i;
}
return -1;
},
remove : function(o){
var index = this.indexOf(o);
if(index != -1){
this.splice(index, 1);
}
}
});

/*====================String====================*/
Ext.apply(String.prototype, {
trim : function() {
return this.replace(/(\s*$)/g, "").replace(/(^\s*)/g, "");//先去掉结尾空格,再去掉开头空格。
},
format : function() {
var args = Array.prototype.slice.call(arguments, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
formatAry : function() {
var a=arguments;
if(typeof arguments[0]=="object"){
a=arguments[0];
}
var args = Array.prototype.slice.call(a, 0);
return this.replace(/\{(\d+)\}/g, function(m, i){return args[i];});
},
zero2int: function() {
if(parseInt(this)!=0)return parseInt(this);
return parseInt(this.replace(/^0/,""));
},
clearZero: function(){
var t=""+this;
if(t[0]=="0"){
t=this.replace(/^0/,"");
t=clearZear(t);
}
return t;
},
string2int: function(){//前面n个0的字符串变数字
var t=""+this;
while((/^0/.test(t)))t=t.replace(/^0/,"");
return /^\d+$/.test(t)?parseInt(t):t;
}
});

/*====================Function====================*/
Ext.apply(Function.prototype, {
createCallback : function(/*args...*/){
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
},
createDelegate : function(obj, args, appendArgs){
var method = this;
return function() {
var callArgs = args || arguments;
if(appendArgs === true){
callArgs = Array.prototype.slice.call(arguments, 0);
callArgs = callArgs.concat(args);
}else if(typeof appendArgs == "number"){
callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
var applyArgs = [appendArgs, 0].concat(args); // create method call params
Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
}
return method.apply(obj || window, callArgs);
};
},
defer : function(millis, obj, args, appendArgs){
var fn = this.createDelegate(obj, args, appendArgs);
if(millis){
return setTimeout(fn, millis);
}
fn();
return 0;
},
createSequence : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
var retval = method.apply(this || window, arguments);
fcn.apply(scope || this || window, arguments);
return retval;
};
},
createInterceptor : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
fcn.target = this;
fcn.method = method;
if(fcn.apply(scope || this || window, arguments) === false){
return;
}
return method.apply(this || window, arguments);
};
}
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值