我正在嘗試使用jQuery Ajax和Spring WebFlow構建應用程序。我可以送價值控制器,但使用jQuery沒有得到全部頁面的響應,而不是具體的<script>
Ajax響應不適用於Spring Webflow
使Ajax調用
$.ajax({
type:"POST",
data:country,
url:$("#welcomeForm").attr("action")+"&_eventId_country&ajaxSource_country"+"&countryName="+country,
success:function(states){
console.log(states);
}
});
Flow.xml:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/webflow" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var class="com.model.Welcome" name="welcome"/>
<on-start>
<evaluate expression="springWebFlow.countryList()" result="flowScope.countries"/>
</on-start>
<view-state id="welcome" model="welcome" redirect="false" view="/WEB-INF/views/welcome.jsp">
<transition on="country" bind="false">
<evaluate expression="springWebFlow.stateList(flowRequestContext)" result="flowScope.states" result-type=""/>
</transition>
<transition on="welcome" to="actionState1"/>
</view-state>
<end-state commit="false" id="actionState1" view="/WEB-INF/views/myDetails.jsp"/>
</flow>
控制器:
public @ResponseBody List<State> stateList(RequestControlContext context) throws Exception {
List<State> states= new ArrayList<State>() ;
State stateName= new State();
String countryName= context.getRequestParameters().get("countryName");
if(countryName.equals("India")){
stateName.setStateName("Delhi");
states.add(stateName);
}
return states;
}
我不想使用Spring JavaScript而不使用Tiles。我可以向控制器發送請求,但無法獲得響應(獲取整個頁面)或在頁面中顯示響應。
如果您將整頁作爲響應,聽起來像是您調用了錯誤的控制器方法。你嘗試過調試嗎?還有什麼'stateS',一些類變量? JavaScript和Java代碼中的「州」是什麼?在控制器上,它不會被保存在任何地方,並且在AJAX調用中,您正在提醒未在函數中定義的變量。 – t0mppa
你可以發佈你收到的整個頁面回覆以及發佈的網址嗎? –
它只是一個html頁面 –