我不确定为什么会这样。我有一个struts表单,会发布到我的struts action的方法:
<s:form data-dojo-type="dijit/form/Form" action="SaveRec" method="POST"
enctype="multipart/form-data" theme="simple" id="frmRecord">
<div class="item">
...
基本上,我只是在浏览器中点击链接htp://example.com:8080 / Test / SaveRec,我将获得一个可行的页面,但在使用这些代码后,我将收到404错误(POST {{ 3}} 404(未找到)):
dojo.connect(dojo.byId('btnSave'), 'onclick', function(event){
// The parameters to pass to xhrPost, the message, and the url to send it to
// Also, how to handle the return and callbacks.
var xhrArgs = {
form: dojo.byId("frmRecord"),
handleAs: "json",
load: function(data){
console.log("Message posted. " + data);
},
error: function(error){
console.log("Message failed to post, " + error);
}
}
console.log("Message being sent...");
// Call the asynchronous xhrPost
var deferred = dojo.xhrPost(xhrArgs);
});
PS:我可以运行invocation.invoke()
并在我的拦截器中打印出消息
更新
好吧,我认为问题是返回类型的动作,我已经将拦截器添加到动作中,但是,我仍然无法使用getter来检索值:
<struts>
<package name="testJson" extends="json-default">
<action name="SaveRec" class="com.xyz.Test" method="saveRec">
<interceptor-ref name="json">
<param name="contentType">application/json</param>
</interceptor-ref>
<result name="success" type="json">
<param name="root">saveResult</param>
</result>
</action>
...