2016-01-06 41 views
0

目前我做一些代码重构,并尝试通过concatentation取代一代查询字符串,以JSON对象的序列化序列化数组查询字符串参数

来源:

$.ajax({ 
    url:'./services/DataService/getDetails?metric=9&'+dashBoards.getFilter()+'groupby=quarter&'+dashBoards.options.time.start1+'&'+dashBoards.options.time.end1+'&peergroup='+dashBoards.options.peerGroup, 
    type:"GET", 

要:

$.ajax({ 
    url:'./services/DataService/getDetails', 
    data: jsonObject, 
    type:"GET", 

几乎一切正常,除了一件事情。如果jsonObject包含数组字段,它看起来在查询字符串这样的:

...?metric[]=1&metric[]=3 

而不是

...?metric=1&metric=3 

有没有办法,我该如何解决?谢谢!

+1

你必须在'POST'类型的数据传递而不是'GET'和阿贾克斯'data'你可以把它像你所提到的。你也可以像'data:JSON.stringify(jsonObject)'那样做,并使用'POST'类型。 –

+0

@ParthTrivedi'JSON.stringify'不需要,OP不发送JSON – Hacketo

+0

只有改变'type:“GET”'到'type:“POST”' –

回答