Sencha Touch中按鈕事件實現案例
作者:佚名
Sencha Touch中按鈕事件實現案例是本文要介紹的內容,主要是來了解Sencha Touch中Ext.Ajax.request調用WebService方法實例,來看詳細內容。
Sencha Touch中按鈕事件實現案例是本文要介紹的內容,主要是來了解Sencha Touch中Ext.Ajax.request調用WebService方法實例,我們經常在數據庫中獲取數據,并顯示到界面,用Ext.Ajax.request調用WebService方法:
- Ext.setup({
- icon: 'icon.png',
- tabletStartupScreen: 'tablet_startup.png',
- phoneStartupScreen: 'phone_startup.png',
- glossOnIcon: false,
- onReady: function () { //
- //創建一個Panel控件,在Panel控件中創建一個Button按鈕
- var panel = new Ext.Panel({
- fullscreen: true, //全屏顯示
- layout: {
- type: 'vbox',
- pack: 'center' //顯示在Panel控件中的中心
- //align: 'stretch' //按鈕顯示方式,'stretch' 為按鈕伸長到Panel控件的寬度
- },
- items: [ //顯示內容項
- new Ext.Button({ //創建一個按鈕
- ui: 'decline', //
- text: 'Ajax', //按鈕顯示文字
- handler: function () { //按鈕事件
- //創建一個ajax請求對象
- var resp = Ext.Ajax.request({
- method: "post",
- headers: { 'Content-Type': 'application/json;utf-8' },
- //調用的WebService文件,testAjax就是WebService的方法
- url: "../Services/WebService.asmx/testAjax",
- //testAjax方法的參數
- jsonData: { Name: "測試fnAajxReader方法" },
- async: true, //異步執行
- success: function (response, opts) { //成功后執行
- //得到返回的數據
- var sResult = response.responseText;
- var o = Ext.decode(sResult);
- Ext.Msg.alert('提示', o['d'], Ext.emptyFn);
- },
- failure: function (response, opts) { //失敗后執行
- Ext.Msg.alert('提示', response.responseText, Ext.emptyFn);
- }
- });
- }
- })
- ]
- });
- }
- });
- 后臺的WebService.asmx文件的testAjax方法:
- [WebMethod]
- public string testAjax(string Name)
- {
- Dictionary<string, string> oDic = new Dictionary<string, string>();
- oDic.Add("Name", Name);
- oDic.Add("Value", "testAjax");
- return Transform.ToJsonString(oDic); //轉換成json字符串
- }
小結:Sencha Touch中按鈕事件實現案例的內容介紹完了,希望通過本文的學習能對你有所幫助。
責任編輯:zhaolei
來源:
互聯網