Extjs learning notes (5) _ Ajax example

Source: Internet
Author: User

Extjs is very simple to use Ajax. See 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">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<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>
</Head>
<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 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>
</Html>

2. Server getdata. ashx Using system. Web;
Using system. Web. Services;

Namespace ajax_wcf
{
/// <Summary>
/// $ Codebehindclassname $ abstract description
/// </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;
}
}
}
}

Running effect:


Please indicate from "Yang Guo under the bodhi tree" http://www.cnblogs.com/yjmyzz/archive/2008/08/30/1279918.html

Related Article

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.