Search code examples
javascriptjqueryruby-on-railsget

jQuery how to put hash value in GET request parameter


I send the get request as this way, and the goal is to download an excel file.

var filter = {
  'type': 'credit',
  'status': 'fail',
  'invoice_type': 'invoce',
}
var url = `/download_money_report?filter=${filter}`
window.location.assign(url);

But in the backend(Rails), I get the parameter like this { "filter" => "[object Object]" }

How should I do to make it become

{ 
  "filter" => {
    "type" => 'credit',
    "status" => 'fail',
    "invoice_type" => 'invoce',
  }
}

Solution

  • You have to use JSON.Stringify(filter) before attaching it to the URL and parse back in the Rails