加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Sencha Touch的Ext.Ajax.request调用WebService方法实例

发布时间:2020-12-16 00:35:21 所属栏目:百科 来源:网络整理
导读: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({ f

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]
publicstring testAjax(string Name)
{
Dictionary<string,string> oDic = newDictionary<string,string>();
oDic.Add("Name",Name);
oDic.Add("Value","testAjax");

return Transform.ToJsonString(oDic);//转换成json字符串 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读