Manual:Core:Ext.Ajax 类
来源:互联网 发布:python udp recvfrom 编辑:程序博客网 时间:2024/05/22 01:26
Ext.Ajax类是一个简单而清晰的XHR封装器,允许你快速而有效地执行AJAX请求。在本教程中,我们将会讨论除了公共方法request()外,还有怎么使用明文报码(Cleat Text)或解码JSON对象的强大扩展方法。
配置项对象
已经全部归档到Ext.Ajax Class Doc
配置项 类型
url 字符类型 必须的
params 已编码JSON的对象 可选的
method 'GET' 或 'POST' 可选的
success 匿名函数对象或已声明好的函数 必须的
failure 匿名函数对象或已声明好的函数 必须的
timeout XHR超时的毫秒数 可选的
简单的例子
下面的例子会执行一个请求和完成Ext.MessageBox.alert
JavaScript:
- Ext.Ajax.request({
- url : 'ajax.php' ,
- params : { action : 'getDate' },
- method: 'GET',
- success: function ( result, request ) {
- Ext.MessageBox.alert('Success', 'Data return from the server: '+result.responseText);
- },
- failure: function ( result, request) {
- Ext.MessageBox.alert('Failed', 'Successfully posted form: '+action.date);
- }
- });
PHP服务器端:
- // ajax.php
- <?php
- if ($_REQUEST['action'] == 'getDate') {
- echo date('l dS /of F Y h:i:s A');
- }
- ?>
进阶例子 - 转换.responseText结果到JSON
HTML + javascript
- <div>
- 这里是一个简单的请求。
- </div>
- <div id="subButton"></div>
- <textarea id="log" cols="40" rows="10"></textarea>
- <script type="text/javascript">
- function doJSON(stringData) {
- try {
- var jsonData = Ext.util.JSON.decode(stringData);
- Ext.MessageBox.alert('Success', 'Decode of stringData OK
- jsonData.date = '+ jsonData.date);
- }
- catch (err) {
- Ext.MessageBox.alert('ERROR', 'Could not decode ' + stringData);
- }
- }
- function doAjax() {
- Ext.Ajax.request({
- url : 'ajax.php' ,
- params : { action : 'getDate' },
- method: 'GET',
- success: function ( result, request) {
- var textArea = Ext.get('log').dom;
- textArea.value += result.responseText + "/n";
- //Ext.MessageBox.alert('Success', 'Data return from the server: '+ result.responseText);
- doJSON(result.responseText);
- },
- failure: function ( result, request) {
- Ext.MessageBox.alert('Failed', 'Successfully posted form: '+result.date);
- }
- });
- }
- var button = new Ext.Button('subButton', {
- text: 'Click to submit an AJAX Request',
- handler: doAjax
- });
- </script>
PHP 服务器端
- <?
- if ($_REQUEST['action'] == 'getDate') {
- echo "{date: '" . date('l dS /of F Y h:i:s A') . "'}";
- }
- ?>
转载自:http://extjs.com/learn/Manual:Core:Ext.Ajax_%28Chinese%29
译者姓名:Frank
译者博客:http://www.ajaxjs.com/blog/
- Manual:Core:Ext.Ajax 类
- Manual:Core:Working with JSON (EXT 与json的交互)
- Ext.Ajax类
- Ext Core
- Ext框架学习 (三) Ext.Ajax类
- Ext源码概览(Manual:Ext Source Overview)
- ajax Ext
- ext--Ajax
- Ext Ajax
- Ext.core.DomHelper用法
- EXT 的继承 Manual:Intro:Inheritance
- EXT 的继承 Manual:Intro:Inheritance
- EXTJS4之常用工具类与函数--Ext.core.Element
- ExtJs4常用工具类与函数之Ext.core.DomHelper
- Manual:Ext Source Overview (EXT 学习原始资料)
- Ext-API详解--core/Ext.js
- Ext-API详解--core/Ext.js
- Ext-API详解--core/Ext.js
- EXA OPC and HIS OPC 连接
- EXT 的继承 Manual:Intro:Inheritance
- Oracle存储过程实例
- ArcMap注记多行显示问题的解决方法
- 高负载门户网站系统架构
- Manual:Core:Ext.Ajax 类
- GDB 内存断点
- Manual:Core:Working with JSON (EXT 与json的交互)
- 背景图片随网页内容自动调整大小
- CE5.0关于设备管理器的源码分析
- Manual:Ext Source Overview (EXT 学习原始资料)
- JavaScript回车切换焦点
- 用中断使屏幕变成红色的
- Manual:Utilities:Function(EXT 内建函数对象)