ITeye博客

Ext同步与异步请求(转自garnettcwm)

20444465 · 2011-06-01 15:43 · ExtJs · Web前端 · Ajax · EXT · json · Markdown

EXTJS 同步和异步请求

同步方式请求:

  1. var  conn = Ext.lib.Ajax.getConnectionObject().conn;
  2. conn.open( "GET" ,  'your url' , false );
  3. conn.send( null );
  4. alert(conn.responseText);
  5. var respText = Ext.decode(conn.responseText);  //若符合JSON规范,转化为JSON数组

或者

  1. var conn = Ext.lib.Ajax.getConnectionObject().conn;
  2. conn.open("POST", url, false);
  3. conn.send("发送到服务器端的信息");
  4. data = conn.responseText;
  5. alert(data);
  6. var respText = Ext.decode(conn.responseText);  //若符合JSON规范,转化为JSON数组

关键是要设置false这个参数

异步方式请求:

  1. Ext.Ajax.request({
  2. url :  'listpublishersms.action' ,
  3. success :  function (response, options) {
  4. var  temp =  "<chart caption='"
  5. + startField.getValue().dateFormat( "Y-m-d" )
  6. +  "至"
  7. + endField.getValue().dateFormat( "Y-m-d" )
  8. +  "' baseFontSize='12' formatNumberScale='0' showBorder='1'>" ;
  9. var  responseArray = Ext.util.JSON
  10. .decode(response.responseText);
  11. alert(responseArray.list.length);
  12. for  ( var  i = 0;i < responseArray.list.length ;i++) {
  13. var  pname = responseArray.list[i].pname;
  14. var  count = responseArray.list[i].count;
  15. temp +=  "<set label='"  + pname
  16. +  "' value='"  + count +  "'/>" ;
  17. }
  18. temp +=  "</chart>" ;
  19. chart_chart.setDataXML(temp);
  20. }
  21. });

Ext.decode()是将json字符串转换成对象;Ext.encode()是将对象转换成json字符串

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。