2016-01-06 44 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」' –

回答