【发布时间】:2012-11-23 13:11:22
【问题描述】:
我正在尝试通过 url 中的查询字符串/变量发送序列化数据。如您所知,当我们在 js 中进行序列化时,它会自己构建一个查询字符串。我正在将此数据发送到用 django 编写的服务器端。我该怎么做或如何在 django 代码中收集数据。
这就是我正在做的。
selected = $('input:checkbox:checked').serialize();
这给了我multiselect_select_month=10&multiselect_select_month=11&multiselect_select_month=05的结果
我想在一个带有其他变量的 url 中发送它,并将孔字符串 (multiselect_select_month=10&multiselect_select_month=11&) 收集到一个变量中。
像
serialized = 'multiselect_select_month=10&multiselect_select_month=11'
在服务器端我正在写serialized = request.GET.get('serialized', '')
如何在单个变量中发送该序列化字符串(这是一个查询字符串),以便我可以在服务器端捕获它。
注意:我还想用上面的序列化数据发送其他变量。
【问题讨论】:
-
那么,您的问题到底是什么?
-
我的问题是如何在单个变量中发送该序列化字符串(这是一个查询字符串),以便我可以在服务器端捕获它。
-
只需将其作为参数附加到您的 HTTP GET / 链接 / 但是您正在联系服务器:
"htpp://some.request.com/?" + serialized -
是的,我试过这个,但它只给了我第一个'multiselect_select_month'。我需要一个变量中的所有“multiselect_select_month”,并且不知道它可能包含多少个“multiselect_select_month”。
-
啊,我明白了。每个
multiselect_select_month都会覆盖它之前的那个。我看看能不能给个答案。
标签: javascript python django serialization query-string