Earlier i was using ajax() function.
But since it is not possible to send js array or json object, I am
trying $.ajax function.
--- View ---
var jsonObjects = [{id:1, name:"amit"}, {id:2, name:"ankit"},{id:3,
name:"atin"},{id:1, name:"puneet"}];
$.ajax({
url: "{{=URL('myControllerName')}}",
type: "POST",
context: document.body,
data: {students: JSON.stringify(jsonObjects) },
dataType: "json",
success: function(){
alert('ok');
}
});
--- end View ---
In controller, how do I access the data?
Somebody has give the code for grails as :---
//this code is written in grails
import grails.converters.JSON;
List<JSON> students = JSON.parse(params.students) //students in
request params is parsed to json objects and stored in the List
println "Student id: " + students[0].studentId //first element of
the students list is accessed as a map holding a key studentId
In web2py, how to port this code?
Thanks,
Vineet