ExtJS Learning Notes (5) _ajax Example

Source: Internet
Author: User
Tags html page tostring

ExtJS the use of Ajax is very simple, look at the following code:

1.Html page:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<link rel= "stylesheet" type= "Text/css" href= "Js/ext2.2/resources/css/ext-all.css"/>
<script type= "Text/javascript" src= "Js/ext2.2/adapter/ext/ext-base.js" ></script>
<script type= "Text/javascript" src= "Js/ext2.2/ext-all.js" ></script>
<title></title>
<body>
<script type= "Text/javascript" >
Ext.onready (function () {
var Fnajaxdemo = function () {
var MyData;
Ext.Ajax.request ({
URL: "Getdata.ashx?name=" + encodeURIComponent (ext.get ("name"). Dom.value),//server-side address
Success:function (Request) {
MyData = Request.responsetext; Server-side Text data
Ext.MessageBox.alert ("Return value", MyData);
},
Failure:function () {
Alert ("failure!");
}
});
}
Ext.get ("Btntest"). On ("click", Fnajaxdemo);

})
</script>

<input id= "name" value= "Jimmy" name= "name"/>
<button id= "btntest" > Get server information </button>

</body>

2. Service-side Getdata.ashx

using System.Web;
using System.Web.Services;

namespace Ajax_WCF
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetData : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request["name"] != null && context.Request["name"].ToString()!="")
{
context.Response.Write("Hello World," + context.Request["name"].ToString() + "!");
}
else
{
context.Response.Write("Hello World");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.