【发布时间】:2012-10-14 15:55:48
【问题描述】:
我正在尝试对我的 webflow 进行 Ajax 调用,并且只想为每个视图状态刷新页面的内容部分。
function proposedInsured(){
("#myForm").submit(function() {
$.ajax({
type: "POST",
data: $("#myForm").serialize(),
url: $("#myForm").attr("action") + "&_eventId=nextpage&ajaxSource=print_message",
success: function(response) {
alert("success" + response);
$('#content').html(response);
},
error: function(response) {
alert("error" + response);
}
});
return false;
});
}
流.xml
<view-state id="firstPage" view="firstPage" >
<transition on="nextpage" to="proposedInsured"/>
</view-state>
<view-state id="proposedInsured" model="policyBean" view="proposedInsured">
<binder>
<binding property="name" />
</binder>
<on-entry>
<evaluate expression="pocContent.getContent('proposedInsured',productId)" result="flowScope.content"/>
<render fragments="content"/>
</on-entry>
<transition on="nextpage" to="address" />
</view-state>
<subflow-state id="address" subflow="address">
<transition on="saveAddress" to="nextpage">
<evaluate expression="policyBean.setAddressDetail(currentEvent.attributes.addressDetail)"/>
</transition>
</subflow-state>`
在首页上的 NextPage 提交按钮的单击事件中,正在触发我的 ajax 脚本,该脚本会调用我的 webFlow。
firstPage(视图部分使用Thymeleaf2.0.12)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
<body>
<div id="content" tiles:fragment="content">
<form id="myForm" method="post" th:action="${flowExecutionUrl}">
<input id="print_message" type="button" value="NextPage" name="_eventId_nextPage" onclick="proposedInsured();"/>
</form>
</div>
</body>
</html>
proposedInsured.html
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
<body>
<div id="content" tiles:fragment="content">
<form id="myForm" name="myForm" method="POST">
...
</form>
</div>
</body>
</html>
模板.html
<div id="page-container">
<div id="header" th:fragment="header">
...
</div>
<div id="content" th:fragment="content">
....
</div>
</div>
问题:获取整个页面(标题和内容)以响应我的 Ajax 调用。据我了解<render fragment="content"> 应该从整个页面中提取内容片段并将其传递给客户端。并没有真正理解它的含义。我该怎么处理这个?
我观察到的第二件事是它对流进行了 2 次调用,一个是失败的 Post,另一个是返回响应的 Get。谁能解释一下为什么会这样?
【问题讨论】:
标签: jquery ajax spring-webflow thymeleaf