Я использую функцию $ .ajax для отправки данных json на серверную функцию.
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');
}
});
Как получить доступ к данным в функции сервера?
Кто-то дал код для грааля как: ---
//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
Я хочу сделать это в веб-среде Python, а именно. web2py.
Пытался получить доступ к нему как params.students и request.students, но безуспешно.
Какой правильный синтаксис для доступа к отправленным данным? (Я проверил jQuery API, но не смог найти то же самое).
Спасибо
Vineet