ฉันกำลังพยายามสร้างแอปพลิเคชันโดยใช้ jQuery Ajax และ Spring WebFlow ฉันสามารถส่งค่าไปยังคอนโทรลเลอร์ได้ แต่ไม่ได้รับทั้งหน้าเป็นการตอบกลับแทนที่จะเป็นเฉพาะ <script>
การโทร Ajax โดยใช้ jquery
$.ajax({
type:"POST",
data:country,
url:$("#welcomeForm").attr("action")+"&_eventId_country&ajaxSource_country"+"&countryName="+country,
success:function(states){
console.log(states);
}
});
โฟลว์.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
คืออะไร ตัวแปรคลาสบางตัวคืออะไรstates
มีไว้เพื่ออะไรทั้งในโค้ด JavaScript และ Java บนคอนโทรลเลอร์จะไม่ถูกบันทึกทุกที่และในการเรียก AJAX คุณกำลังแจ้งเตือนตัวแปรที่ไม่ได้กำหนดไว้ในฟังก์ชัน - person t0mppa   schedule 26.01.2014