I need to get a list from mvc controller to view using jquery ajax. how can i do that. this is my code. Its alerting error message.
publ
$(document).ready(function () {
var data = new Array();
$.ajax({
url: "list",
type: "Get",
data: JSON.stringify(data),
dataType: 'json',
success: function (data) {
$.each(data, function (index) {
// alert("id= "+data[index].id+" name="+data[index].name);
$('#myTable tbody').append("" + data[index].id + " " + data[index].name + " ");
});
},
error: function (msg) { alert(msg); }
});
});
@Controller
public class StudentController
{
@Autowired
StudentService studentService;
@RequestMapping(value= "/list", method= RequestMethod.GET)
@ResponseBody
public List dispalyPage()
{
return studentService.getAllStudentList();
}
}