$ .param()生成的查询字符串包括数组的方括号 [英] Query String generated by $.param() include square brackets for array
本文介绍了$ .param()生成的查询字符串包括数组的方括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的对象:
var queryObject= {
name: 'Shwetanka',
subjects: ['Mathematics', 'Physics', 'Computers'],
stream: 'science'
};
当我使用 $。param(queryObject)<创建查询字符串时/ code>我将此作为查询字符串:
When I create query string with this using $.param(queryObject)
I get this as query string:
name=Shwetanka&subjects%5B%5D=Mathematics&subjects%5B%5D=Physics&subjects%5B%5D=Computers&stream=science
预期: name = Shwetanka&臣=数学和科目=物理和科目=计算机& stream =科学
如何避免 []
由查询字符串中的方法添加同名的params。在后端,我使用 struts2 阅读params。
How do avoid []
added by the method in the query string for params with same name. In the backend I'm using struts2 to read params.
推荐答案
我找到了解决方案。我只需要在 $。param(queryObject,true)
中传递'traditional = true'。这会生成我想要的查询字符串。
I've found the solution. I just have to pass 'traditional=true' in $.param(queryObject, true)
. This generates the query string i want.
这篇关于$ .param()生成的查询字符串包括数组的方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文