编程语言
首页 > 编程语言> > python-$.ajax函数:发送json数据:在服务器端函数进行解析

python-$.ajax函数:发送json数据:在服务器端函数进行解析

作者:互联网

我正在使用$.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');
  }

});

在服务器端功能中,如何访问数据?

有人将grails的代码指定为:—

//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 Web框架中执行此操作. web2py.

试图以params.students和request.students的身份访问它,但是没有运气.

访问已发送数据的正确语法是什么? (我检查了jQuery API,但找不到相同的代码).

谢谢,

藤蔓

解决方法:

你很困惑.

“如何访问服务器端的数据”与jquery无关,与服务器端的Web框架无关.

您需要从请求对象中提取数据;该web2py文档在这里:http://web2py.com/book/default/chapter/04#request

标签:web2py,ajax,python
来源: https://codeday.me/bug/20191101/1985328.html