-
Oct 21st, 2011, 11:32 AM
#1
using jquery to make ajax call. not able to invoke URLin controller
Hi,
I am using jquery to make an ajax call in my JSP page. i have specified the URL and wrote a method to do the handling in my controller. the method is not being executed. Request you to help in identifying the problem. Please note that i am not using annotation driven option in my dispatcher.
here is my code for jquery.
<script type="text/javascript">
function loadStates() {
var country_value = $("#country option:selected").val();
$.ajax({
url: '/states.htm',
data: ({country_id : country_value}),
success: function(data) {
alert('inside function');
}
});
}
</script>
this is how i am invoking this function in my jsp using onchange event
<form:select path="country" id="country" onChange="loadStates();">
<form:option value="S" label="Select Country"></form:option>
<c:forEach items="${countryList}" var="country">
<form:option value="${country.countryId}" label="${country.name}"></form:option>
</c:forEach>
</form:select>
here is my handler in the controller
@RequestMapping(value="/states.htm",method = RequestMethod.GET)
@ResponseBody
public List states(@RequestParam int country_id) {
System.out.println("country id is "+country_id);
List statesList=customerDAO.listStates(country_id);
return statesList;
}
here is my code in DAO that returns states list based on country value
public List<states> listStates(int id) {
return hibernateTemplate.find("from states where country_id="+id+" order by name");
}
this is my dispatcher code to invoke the controller
<bean id="mycustomerDAO" class="customer.customerDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<bean name="/customer*.htm" class="customer.customerController" >
<property name="customerDAO" ref="mycustomerDAO" />
</bean>
if using annotation driven is compulsory please provide an example of how to map these controller classes using annotation
-
Oct 24th, 2011, 03:55 AM
#2
problem solved
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules