javascript - Pass value of multiple input fields in jQuery ajax? -




i have multiple input fields, like

  <p>filter gender</p>   <select class="filter-users">      <option value="female">female</option>      <option value="male">male</option>    </select>    <p>filter city</p>       <input class="filter-users" type="text" name="city"> 

how create request url these 1 or of these inputs

$.ajax({   url: "/users/filter",   type: "get",    data: {      city: city,      gender: gender   },   success: function(response) {    } }); 

how make ajax request every time on of filter inputs changed? example send new request when on option change, or text input entered? trying explain is, there no submit button. requests needs made everytime 1 of these fields changes

you can use serializearray, this:

$.ajax({   url: "/users/filter",   type: "get",    data: $("form").serializearray(),   success: function(response) {   } }); 

or can use serialize in case don't need json url-encoded parameters.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -