`
raisun_1988
  • 浏览: 113263 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

ExtJs学习笔记(5)_Ajax示例

    博客分类:
  • Java
阅读更多

 

ExtJs学习笔记(5)_Ajax示例

ExtJs对于Ajax的使用非常简单,看下面的代码:

 

1.Html页:

 

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<linkrel="stylesheet"type="text/css"href="js/ext2.2/resources/css/ext-all.css"/>
<scripttype="text/javascript"src="js/ext2.2/adapter/ext/ext-base.js"></script>
<scripttype="text/javascript"src="js/ext2.2/ext-all.js"></script>
<title></title>
</head>
<body>
<scripttype="text/javascript">
Ext.onReady(
function(){

varfnAjaxDemo=function(){
varmydata;
Ext.Ajax.request({
url:
"GetData.ashx?name="+encodeURIComponent(Ext.get("name").dom.value),//服务器端地址
success:function(request){
mydata
=request.responseText;//服务器端文本数据
Ext.MessageBox.alert("返回值",mydata);
},
failure:
function(){
alert(
"failure!");
}
});
}

Ext.get(
"btnTest").on("click",fnAjaxDemo);


})
</script>


<inputid="name"value="Jimmy"name="name"/>
<buttonid="btnTest">获取服务端信息</button>

</body>
</html>


2.服务端GetData.ashx
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->usingSystem.Web;
usingSystem.Web.Services;


namespaceAjax_WCF
{
///<summary>
///$codebehindclassname$的摘要说明
///</summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo
=WsiProfiles.BasicProfile1_1)]
publicclassGetData:IHttpHandler
{

publicvoidProcessRequest(HttpContextcontext)
{
context.Response.ContentType
="text/plain";
if(context.Request["name"]!=null&&context.Request["name"].ToString()!="")
{
context.Response.Write(
"HelloWorld,"+context.Request["name"].ToString()+"!");
}
else
{
context.Response.Write(
"HelloWorld");
}
}

publicboolIsReusable
{
get
{
returnfalse;
}
}
}
}


运行效果:


转载请注明来自"菩提树下的杨过"http://www.cnblogs.com/yjmyzz/archive/2008/08/30/1279918.html

 

欢迎加入:http://www.itpob.cn/bbs

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics