extjs ajax是一個實例化好的單例類 能夠直接使用php
Ext.Ajax.request({ url:"user.php", params:{ id:1 }, success:function(response, opts){ console.log(response.responseText); } });
參數html
binary : Boolean | 是否爲二進制數據 默認爲false |
設置爲true後 返回值受影響 |
cors : Boolean | 是否跨域 默認爲false | 設置爲true後 能夠跨域 |
DisableCachingParam:String | 修改get請求禁止緩存名稱 默認爲_dc | 能夠修改DisableCaching名稱 |
listeners : Object | 事件監聽 | 能夠添加事件監聽 |
withCredentials : Boolean | 設置withCredentials | 發送跨域請求憑據 |
ajax和前臺交互ajax
<div id="el"></div>
Ext.get('el').load({ url: 'myPage.php', scripts: true, params: { id: 1 } });
$arr = array( "id" => 2, "name" => "sadsads", "email" => "sadasdsadsas" ); $data = json_encode($arr); echo $data;
ajax回調函數json
Ext.get('el').load({ url: 'user.php', scripts: true, params: { id: 1 }, callback:function(obj,status,response,options){ }, failure:function(obj,response,options){ }, success:function(obj,response,options){ } });
ajax request 跨域
form屬性 能夠自動獲取一個form的值緩存
jscors
Ext.get("b").on("click",function(){ Ext.Ajax.request({ url: 'user.php', method: 'post', params: { id:1 }, form: 'myform', callback:function(obj,status,response,options){ }, failure:function(obj,response,options){ }, success:function(obj,response,options){ } }); })
html函數
<form id="myform"> <input name="username"> <input name="password"> <input id="b" type="button" value="提交"> </form>
phppost
$arr = array( "id" => $_POST["id"], "name" => $_POST["username"], "email" => $_POST["password"] ); $data = json_encode($arr); echo $data;
jsonData屬性 能夠以json方式傳遞數據url
js
var data = {id:2,username:"sdsds",password:"ssdss"}; Ext.get("b").on("click",function(){ Ext.Ajax.request({ url: 'user.php', method: 'post', jsonData:data, callback:function(obj,status,response,options){ }, failure:function(obj,response,options){ }, success:function(obj,response,options){ } }); })
html
<button id="b">按鈕</button>
php
$arr = file_get_contents("php://input"); $arr = json_decode($arr,true); echo $arr['id'];