微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

原文地址:https://www.jb51.cc/ajax/164972.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐