1

I have this form:

<form id="filter_form">
   <select name="type">
      <option value="second">second</option>
   </select>
   <input type="checkbox" name="city[]" value="new_york" />
   <input type="checkbox" name="city[]" value="washington" />
</form>

and this event in js:

    $('#filter_form').on('change', function () {
        $.ajax({
            url: "properties",
            method: 'GET',
            data: $("#filter_form").serialize(),
            success: function(result){
            }
        });
    });

In this moment the url is built like this:

properties?transaction_type=second&city%5B%5D=new_york&city%5B%5D=washington

but I need

properties?transaction_type=second&city=new_york,washington

How can I make this join?

UPDATE EDIT:

This method will help me but I can't find a way to implement:

array.map(function() { 
    return this.value; 
}).get().join(',');

2 Answers2

0

You don't need the [] as they do no have any semantical meaning in this context. Also they are duplicates and it is best practice to have unique variables.

Remove these for starts and replace with city1 and city2

This is a _GET request and you will be able to access these values from the server as city1 and city2.

If you want them combined into cities

You can write a script on the client side in JS to combine them into one key/value pair.

0

You can add your query string in url

properties?transaction_type=second&city=new_york,washington

var data = 'transaction_type=' + <select_value> + '&city=' + <city_values>;
$('#filter_form').on('change', function () {
    $.ajax({
        url: "properties?" + data,
        method: 'GET',
        success: function(result){
        }
    });
});
Siraj ul Haq
  • 845
  • 9
  • 25