EXT (3) --- Ajax

Source: Internet
Author: User
1 test.html

<HTML>
<Head>
<Title> </title>

<! -- Include ext and app-specific scripts: -->
<SCRIPT type = "text/JavaScript" src = "../adapter/EXT/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../ext-all-debug.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "extstart. js"> </SCRIPT>

<! -- Include ext stylesheets here: -->
<LINK rel = "stylesheet" type = "text/CSS" href = "../resources/CSS/ext-all.css">
</Head>
<Body>
<Div id = "MSG"> </div>
<Div>
Name: <input type = "text" id = "name"/>
<Input type = "button" id = "okbutton" value = "OK"/>
</Div>
<Div id = "MSG"> </div>
</Div>
</Body>
</Html>

2 extstart. js
Ext. onready (function ()...{
Ext. Get ('okclick'). On ('click', function ()...{
VaR MSG = ext. Get ('msg ');
MSG. Load (...{
URL: 'ajax-example. php', // <-- change according to actual conditions
Params: 'name = '+ Ext. Get ('name'). Dom. value,
Text: 'updating ...'
});
MSG. Show ();
});
});

3 ajax-example.php

<? PHP if (isset ($ _ post ['name']) {
Echo 'from server: '. $ _ post ['name'];
}
?>

This mode looks familiar! First obtain the button element, add an anonymous function listener, and click. In event handler, we use an ext built-in class that handles Ajax requests, accepts responses, and updates another element, called updatemanagerupdater. Updatemanager can be used directly or referenced through the load method of element, as we do now (in this example, the element is a div with the ID of "MSG ). When the element. load method is used, the request will be sent after processing and wait for the response from the server to automatically replace the innerhtml of the element. You can simply input the server URL address and add a string parameter to process this request (in this example, the parameter value comes from the value of the "name" element ), the text value is the text prompted when the request is sent. The DIV of the MSG is displayed after the request is sent (because it is hidden by default at the beginning ). Of course, like most ext components, ext. Ajax has many optional parameters, and different Ajax requests have different solutions. Here we only show the simplest one.

The last obscure aspect of AJAX is that the server actually processes requests and returns (resposne. This process will be a server page, a servlet, an HTTP scheduling process, a WebService, or even a Perl or CGI script, that is, HTTP requests that can be processed by a server without being specified. What is unpredictable is that the server returns something about the server and cannot overwrite all possibilities with a standard example ..

 

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.