Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im using spring framework. i need to get list of all doctors of a particular department..

View page:-
XML
<tr>
    <td><form:select path="department" items="${departmentList}" onchange="departmentselected()" /></td>
    <td><form:select path="doctorname" /></td>
    <td><form:input path="appointmentdate" rows="5" cols="30" /></td>
    <td rowspan="2"><input type="submit" value="Search" /></td>



Javascript :-

JavaScript
function departmentselected()
	{
	    var element = document.getElementById("department");
	    var department = element.options[element.selectedIndex].value;
	    //alert(department);
	    $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}/getdoctlist",
            data: {"department": department},
            dataType: "application/json",
            success: function(response) {
                alert("json : "); // here i need to bind the response list to doctor combobox item.
            },
            error: function(error) {
                alert('Failed to get details: ' + error);
            }
        });
	} 



The error displayed while returning while running is "Failed to get details:[object Object]"


Controller page :-

Java
@RequestMapping(value="/getdoctlist", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody  Doctor getdoctlist(@RequestParam("department")String department,HttpServletRequest request, HttpServletResponse response){
		
		Doctor doc = new Doctor();		
		doc.setFirstName("akhil");
		doc.setDepartment("Dentistry");
		  //here i am getting the value in console 
        System.out.println("From control calss = " +department); 
                 //here i am getting the value in console 
        System.out.println("return value : "+ doc.getDepartment() +" and " + doc.getFirstName()); 

return doc;
    }


when it returns to the requested page it shows network error 406.
Thanking you for ur valuable time. Hope i will get a positive response
Posted

1 solution

function departmentselected()
{

var xmlhttp;

if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("Your Id").innerHTML = xmlhttp.responseText;
var xml = xmlhttp.responseText;
}
}

var url = "Your url";

xmlhttp.open("POST", url, true);

xmlhttp.send();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900