問題描述:
如何 從ext前端發送異步請求到 struts的Action後端,並獲取後端的返回信息
解決方案:
1. Ext 前端.js文件中:
Ext.Ajax.request({
url: 'GoodAction_add.do'
,method:'POST'
,params: { // 發送的參數
sForm:sForm
,dbHeight:dbHeight
,sColor:sColor
,sCraft:sCraft
,dbWeight:dbWeight
,dbWidth:dbWidth
,sTypeNum:sTypeNum
}
,scope: this
,success: function(response,action){
var oResponse = Ext.util.JSON.decode(response.responseText);//這裏是將後端outPrint()發出的json串轉爲對象。
alert("success !" + oResponse.msg );
}
,failure:function(){
var oResponse = Ext.util.JSON.decode(response.responseText);
alert("failure !" + oResponse.msg );
}
});
2. Action中:
String msg = "操作成功!";
super.outPrint("{success:true,msg:\"" + msg + "\"}");
return "success";