nzrnfourtwenty nzrnfourtwenty - 9 months ago 33
Javascript Question

How to pass "select" id into an ajax

My ajax script

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

The html form

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

My php

$search = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_SPECIAL_CHARS);

if (isset($search)) {
echo 'Successfully here';

$sql = "SELECT * FROM blabla";

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)


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: