【发布时间】:2014-02-16 20:49:21
【问题描述】:
我正在尝试使用 jQuery Ajax 和 Spring WebFlow 构建应用程序。我可以向控制器发送值,但不能将整个页面作为响应而不是特定的 <script>
使用 jquery 进行 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 代码中的states是什么?在控制器上,它没有保存在任何地方,并且在 AJAX 调用中,您正在警告函数中未定义的变量。 -
您能否发布您获得的完整页面回复以及发布的网址?
-
只是一个html页面
标签: java jquery ajax spring-webflow