日期:2014-05-16  浏览次数:20356 次

Ext js Ajax 基本用法
最近在做一个项目时候用到了使用Ext 进行异步的请求,对Ext.Ajax.request有了点基本的认识
基本结构如下:
Ext.Ajax.request({
    url:'xxx.do',
    method : 'post',// 请求的方式 GET OR POST
    params :  {id : id}, //  传递的参数
    scope:this,      // 修改函数的this对象

//   成功时候的回调函数
    success : function(response, options)
    {
   				
    },

//   失败时候的回调函数
    failure : function(response, options)
   {
    	
   }
});	


在Ext.Ajax.request发送请求后一般由一个servlet进行处理,并且最后放回一个json数据对象作为参数放回
	@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
{

       JSONObject responseJSON = new JSONObject();
       //....................
        response.getWriter().write(responseJSON.toString());
	response.getWriter().flush();
}


前台接收到放回的数据后可以进一步进行处理
success : function(response, options)
{
    	var text = Ext.decode(response.responseText);
 
//       通过text.  来获得对应的值
	if(text.success)
	{

	}