我想通过 ajax 中的 URL 发送数组,并在后端我想在 python 中访问该数组。我怎样才能做到这一点
<!--Java script code -->
var arr[] = [1,2,3];
$.ajax(function(){
url: 'myurl/arr=' + arr,
});
如何在Python中使用'arr'来显示
--编辑--
def use_arr(request)
method = request.GET
list = method.get('arr')
上面是 python View ,我应该在其中使用该数组,但我无法访问该数组以进行显示。
最佳答案
Javascript
$.get('myurl', {arr: JSON.stringify(arr)})
了解有关 $.get 的更多信息:https://api.jquery.com/jquery.get/
Python
import json
# ...
list = json.loads(request.GET['arr'])
关于javascript - 在 python django 中通过 url 发送数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33475124/