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 ..