Query String generated by $.param() include square brackets for array

前端 未结 2 1912
死守一世寂寞
死守一世寂寞 2021-01-15 06:31

I have an object like this:

var queryObject= {
      name: \'Shwetanka\',
      subjects: [\'Mathematics\', \'Physics\', \'Computers\'],
      stream: \'scie         


        
相关标签:
2条回答
  • 2021-01-15 06:39

    When we have fields with same name in a form and it is submitted via GET/POST, it is bound to be send as an array of params with the same name. And the server would be expecting the values as such. So, Even if you somehow remove that [], it ceases to be an array, and the server will get only one value. jQuery param method is designed, with the same thing in mind. Check out examples in http://api.jquery.com/jQuery.param/.

    0 讨论(0)
  • 2021-01-15 06:52

    I've found the solution. I just have to pass 'traditional=true' in $.param(queryObject, true). This generates the query string i want.

    0 讨论(0)
提交回复
热议问题