Hi,
I am using Spring 3 MVC for an application.
On a page, we have a drop down which contains department names so by selecting specific department name by a user we need to display department information on that page. I am using ajax call
I am using onchange event after user selects specific department name from the drop down which calls a javascript function getDepartmentInfo().
getDepartmentInfo() - creates request, prepares URL and passes department name selected
function getDepartmentInfo(deptName) { request = createRequestObject(); if (request == null) { alert("Unable to create request"); } var url = "/departmentInfo?departmentName="+deptName; request.open("GET", url, true); request.onreadystatechange = processDepartmentDetails; request.send(null); }
processDepartmentDetails - to process the response and to display the information.
In Spring Controller :
@Controller public class DepartmentController { @Autowired private DepartmentService departmentService; @RequestMapping(value="/departmentInfo", method=RequestMethod.GET) public String getDepartmentInformation(@ModelAttribute(value="departmentName") String departmentName, Map<String, Object> map) { System.out.println("department Name " + departmentName); map.put("departmentInfo", departmentService.getdepartmentInfo(departmentName)); return "/home"; } }
But, the ajax request is not reaching the controller. Its working fine after I remove the parameter from ajax call i.e.
var url = "/departmentInfo; request.open("GET", url, true); request.onreadystatechange = processDepartmentDetails; request.send(null);
Please let me know how to pass parameter from ajax and handle the request in Spring?
Thanks and Regards,
Chinnu