如何在GAE端获得具有多个选择的所有select值?

时间:2012-06-24 20:01:11

标签: javascript jquery google-app-engine html-select

我在客户端选择如下:

<select multiple="multiple" id="reason" class="input-xlarge">
  <option value="001">reason1</option>
  <option value="002">reason2</option>
  <option value="003">reason3</option>
  <option value="004">reason4</option>
  <option value="005">reason5</option>
</select>

使用以下代码将数据发送到服务器:

var reason = $('#reason').val();
$.ajax({
  data: {'reason': reason},
  ...
});
...

在服务器上我做了:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
arguments = self.request.arguments()
for argument in arguments:
    if self.request.get(argument):
        self.response.out.write(argument+': '+self.request.get(argument)+'<br>')

结果即使选择了几个原因,我也看到了:

reason[]: 002

如何选择所有值?

Upd1 即可。它们在请求中传递为:

reason%5B%5D=001&reason%5B%5D=002&reason%5B%5D=003&reason%5B%5D=004

1 个答案:

答案 0 :(得分:1)

好的,我可以使用以下代码获取所有代码(感谢来自gae irc的 lericson ):

reasons = self.request.get_all('reason[]')
for reason in reasons:
    logging.info(reason)

但我不喜欢它,因为它假设服务器端的字段值被硬编码。所以,我修改了javascript以发送reason.join()而不仅仅是reason