nzrnfourtwenty
nzrnfourtwenty

Reputation: 135

How to pass "select" id into an ajax

My ajax script

function filter(){
  var input1 = $("#advanced-search1").val();
  $.ajax({
     dataType: 'html',
     url: "php/filter.php",
     type: "POST",
     data: input1,
     success: function(response){
           $('#result').html(response);
     }
  });
}

The html form

<form>
 <select id="advanced-search1" name="taskOption">
   <option value="apple">Apple</option>
   .
   .
   .
 </select>
 <input type="submit" onclick="filter()" value="Filter">
</form>
<div id="result"></div>

My question is how to pass the "select" id into an ajax so that it can be processed in the other php file (filter.php)

Upvotes: 1

Views: 761

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167212

The way data works is by using an object... What you are doing is wrong. Replace the data part with:

data: {"key": input1},

And in the server side you should be able to access it using:

$_POST["key"]

Upvotes: 1

Related Questions