1

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)

1 Answer 1

1

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"] 
Sign up to request clarification or add additional context in comments.

11 Comments

okay, and then which variable that i can carry or process in my other php file?
@nzrnfourtwenty It's like whatever you need to replace instead of the key. You can also use data like this: data: {"data": input1},
alright i got it. but can you take a look at my php file over there. I can only see a flash of "successfully here". I think there's something wrong with the if(empty.....)
@nzrnfourtwenty Haven't used filter_input(INPUT_POST, 'key', FILTER_SANITIZE_SPECIAL_CHARS);
it's okay, but do you have any idea for the php side, on how i want to make sure that the second condition will not be executed depends on submit button not from the 'key'
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.