国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

extJS中常用的4種Ajax異步提交方式

2019-11-20 20:58:27
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
/**
復(fù)制代碼 代碼如下:

* 第一種Ajax提交方式
* 這種方式需要直接使用ext Ajax方法進(jìn)行提交
* 使用這種方式,需要將待傳遞的參數(shù)進(jìn)行封裝
* @return
*/
function saveUser_ajaxSubmit1() {
Ext.Ajax.request( {
url : 'user_save.action',
method : 'post',
params : {
userName : document.getElementById('userName').value,
password : document.getElementById('password').value
},
success : function(response, options) {
var o = Ext.util.JSON.decode(response.responseText);
alert(o.msg);
},
failure : function() {
}
});
}
/**
* 第二種Ajax提交方式
* 這種方式將為ext的ajax指定一個(gè)html表單
* 使用這種方式,不需要將待傳遞的參數(shù)進(jìn)行封裝
*
* @return
*/
function saveUser_ajaxSubmit2() {
Ext.Ajax.request( {
url : 'user_save.action',
method : 'post',
form : 'userForm', // 指定表單
success : function(response, options) {
var o = Ext.util.JSON.decode(response.responseText);
alert(o.msg);
},
failure : function() {
}
});
}
/**
* 第三種Ajax提交方式
* 這種方式將為ext的自己的表單進(jìn)行提交
* 使用這種方式,需要使用ext自己的textField組件
*
* @return
*/
function saveUser_ajaxSubmit3() {
// 定義表單
var formPanel = new Ext.FormPanel( {
labelWidth : 75,
frame : true,
bodyStyle : 'padding:5px 5px 0',
width : 350,
defaults : {
width : 230
},
defaultType : 'textfield',
items : [ {
fieldLabel : '用戶名',
name : 'userName',
allowBlank : false
}, {
fieldLabel : '密 碼',
name : 'password'
} ]
});
// 定義窗口
var win = new Ext.Window( {
title : '添加用戶',
layout : 'fit',
width : 500,
height : 300,
closeAction : 'close',
closable : false,
plain : true,
items : formPanel,
buttons : [ {
text : '確定',
handler : function() {
var form = formPanel.getForm();
var userName = form.findField('userName').getValue().trim();
var password = form.findField('password').getValue().trim();
if (!userName) {
alert('用戶名不能為空');
return;
}
if (!password) {
alert('密碼不能為空');
return;
}
form.submit( {
waitTitle : '請(qǐng)稍后...',
waitMsg : '正在保存用戶信息,請(qǐng)稍后...',
url : 'user_save.action',
method : 'post',
success : function(form, action) {
alert(action.result.msg);
},
failure : function(form, action) {
alert(action.result.msg);
}
});
}
}, {
text : '取消',
handler : function() {
win.close();
}
} ]
});
win.show();
}
/**
* 第四種Ajax提交方式
* 這種方式將html的表單轉(zhuǎn)化為ext的表單進(jìn)行異步提交
* 使用這種方式,需要定義好html的表單
*
* @return
*/
function saveUser_ajaxSubmit4() {
new Ext.form.BasicForm('userForm').submit( {
waitTitle : '請(qǐng)稍后...',
waitMsg : '正在保存用戶信息,請(qǐng)稍后...',
url : 'user_save.action',
method : 'post',
success : function(form, action) {
alert(action.result.msg);
},
failure : function(form, action) {
alert(action.result.msg);
}
});
}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桃源县| 白城市| 石林| 奎屯市| 中宁县| 琼结县| 毕节市| 偏关县| 图们市| 宁远县| 通江县| 德格县| 云霄县| 修武县| 辽中县| 吴忠市| 郑州市| 隆林| 麻江县| 滕州市| 广南县| 衡水市| 福州市| 孝昌县| 卓尼县| 商丘市| 肇东市| 牙克石市| 喀喇| 故城县| 莎车县| 三原县| 儋州市| 桂阳县| 民乐县| 遂川县| 武隆县| 科技| 巴彦淖尔市| 福清市| 林口县|