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