我正在嘗試對我的webflow進行Ajax調用,並且只想爲每個視圖狀態刷新頁面的內容部分。Ajax調用WebFlow
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;
});
}
flow.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>`
在下一頁的點擊事件提交第一頁按鈕,我燒我的AJAX腳本,使呼叫我的Webflow。
第一頁(使用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>
template.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個呼叫流動,一個是發佈失敗,另一個是Get,它返回我的響應。任何人都可以解釋爲什麼發生這種情況?
增加了'&fragment = Content'但沒有運氣。此外,嘗試傳遞參數'&ajaxSource = true',如[http://stackoverflow.com/questions/10603177/ajax-spring-webflow]中所述,始終獲取整個頁面作爲響應。 – Shinky
我的地址流程的代碼:' \t \t \t \t \t 子流狀態>' –
Shinky
,我想你有一個'<呈現片段=」「在你的父母流/> ' 」地址的內容「,右? –
rptmat57