我在我的项目中使用struts2-jquery插件。我正在尝试使用<sj:submit>
标记提交表单,如下所示:
<sj:submit id="caseSubmit"
targets="result"
formIds="mainForm"
onCompleteTopics="caseSubmitted"
button="true"/>
此操作的struts.xml映射如下:
<action name="submitAddCase" class="com.xxx.action.AddCaseAction">
<result type="json">
<param name="root">caseId</param>
</result>
</action>
onComPleteTopics代码
$.subscribe('caseSubmitted', function(event,data) {
var indexPre = event.originalEvent.request.responseText.indexOf("<pre>")+5;
var indexPreEnd = event.originalEvent.request.responseText.indexOf("</pre>");
var id = event.originalEvent.request.responseText.substring(indexPre,indexPreEnd);
$("#case_id").val(id);
});
我想要的是使用返回的caseId
来加载同一页面上的其他内容。但,
event.originalEvent.request.responseText
返回caseId
包含在预标记中,如此
<pre>154000</pre>
这是在firefox中返回的方式。在chrome中,它以另一种形式返回。如何在没有包装html的情况下获得caseId的原始值。 现在我使用javascript的substring方法来获取它在chrome中不起作用的值,因为返回格式不同
答案 0 :(得分:1)
替换
$("#case_id").val(id);
与
$("#case_id").val($(id).html());