[英]how to handle events and initiating server request in sencha?
i am working on an application using sencha where i have a login screen with two buttons exit and submit. 我正在使用sencha开发应用程序,其中有两个按钮退出并提交的登录屏幕。 Here i am struggling for handling the events.
在这里,我正在努力处理这些事件。 Also i have two handlers for two buttons.
我也有两个按钮的两个处理程序。 But how can i get the text from the text fields ?
但是如何从文本字段中获取文本? how can i initiate a server request.
我如何发起服务器请求。 Any help is highly appreciated.
非常感谢您的帮助。
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {
var form;
var formBase = {
scroll : 'vertical',
standardSubmit : false,
items: [
{
xtype: 'fieldset',
title: 'Login Screen',
instructions: 'Enter agent number and password to login.',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '45%'
},
items: [
{
xtype: 'textfield',
name : 'username',
label: 'Agent Number',
useClearIcon: true
}, {
xtype: 'passwordfield',
name : 'password',
label: 'Password',
useClearIcon: false
}]
}],
listeners : {
submit : function(form, result){
console.log('success', Ext.toArray(arguments));
},
exception : function(form, result){
console.log('failure', result);
}
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
text: 'Login',
ui: 'confirm',
handler: function() {
alert('Login please wait..');
}
},
{
text: 'Exit',
ui: 'exit',
handler: function() {
alert('Are you sure ?');
}
}
]
}
]
};
if (Ext.is.Phone) {
formBase.fullscreen = true;
} else {
Ext.apply(formBase, {
autoRender: true,
floating: true,
modal: true,
centered: true,
hideOnMaskTap: false,
height: 385,
width: 480
});
}
form = new Ext.form.FormPanel(formBase);
form.show();
}
});
To get the values from the textfield use form.getValues();
要从文本字段获取值,请使用
form.getValues();
. 。 To make a request use:
进行请求使用:
Ext.Ajax.request({
url: 'ajax_demo/sample.json',
method: 'GET',
params:{
username:usernameValue,
password:passValue},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}});
Update 更新资料
First change the name of the fields to user
and pass
then put the following code instead alert('Login please wait..');
首先将字段名称更改为
user
,然后pass
然后输入以下代码,而不是alert('Login please wait..');
Ext.Ajax.request({
url: '140.45.45.20:9010/TService/Sms/Services',
params: form.getValues(),
method: 'GET',
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
//The request was successful - see the response in the response object
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.