Saya mencoba membangun aplikasi menggunakan jQuery Ajax dan Spring WebFlow. Saya dapat mengirim nilai ke pengontrol tetapi tidak mendapatkan seluruh halaman sebagai respons, bukan <script>
spesifik
Melakukan panggilan Ajax menggunakan jquery
$.ajax({
type:"POST",
data:country,
url:$("#welcomeForm").attr("action")+"&_eventId_country&ajaxSource_country"+"&countryName="+country,
success:function(states){
console.log(states);
}
});
Aliran.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>
Pengontrol:
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;
}
Saya tidak ingin menggunakan Spring JavaScript dan tidak menggunakan Tiles. Saya dapat mengirim permintaan ke pengontrol tetapi tidak bisa mendapatkan respons (mendapatkan seluruh halaman) atau menampilkan respons di halaman.
stateS
, beberapa variabel kelas? Untuk apastates
dalam kode JavaScript dan Java? Pada pengontrol itu tidak disimpan di mana pun dan dalam panggilan AJAX Anda memperingatkan variabel yang tidak ditentukan dalam fungsi. - person t0mppa   schedule 26.01.2014