2 回答

TA貢獻1836條經驗 獲得超5個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | $(function(){ $.ajax({ url : 請求的路徑(action), type : "post", //以Post方式發送請求 data : 請求時發送的數據, dataType : json, //返回的數據類型 async : true, //本次請求是否為異步請求 success : function(返回的數據變量){ //請求成功,執行的操作 }, error : function(){ //請求失敗,執行的操作 } }); });
/* 1、action和你普通請求配置一樣 2、請求到后臺后,該怎么處理也和普通請求一樣,dao,mapper什么的都一樣 3、你返回的數據使用JSONObject類來包裝,最后返回的時候把這個對象toString(),依賴的jar包在struts里面提供了 */ |

TA貢獻1794條經驗 獲得超8個贊
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | JsonConfig jsonConfig = new JsonConfig(); jsonConfig.registerJsonValueProcessor(java.util.Date.class,new JsonDateValueProcessor()); JSONArray json = JSONArray.fromObject(list,jsonConfig); ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8"); getResponse().setCharacterEncoding("utf-8"); PrintWriter out = getResponse().getWriter(); out.write(json.toString()); Ext.Ajax.request({ url : '.html', params : {eid : eid}, method : 'POST', callback : function(options, success, response) { var json = Ext.util.JSON.decode(response.responseText); }, scope:this }) |
- 2 回答
- 0 關注
- 2206 瀏覽
添加回答
舉報