<script>
$( "#searchddl" ).chosen().change(function() { // execute query every time select option changes
var val = $( "#searchddl" ).chosen().val(); // get value from selected option
$.ajax({
url: "myphpfile.php", // call external PHP file for query execution
type: "get",
data: {
myselectvalue: val // passes value as GET parameter (?=myselectvalue=val)
},
success: function(response) {
tmp = response // store variable from PHP output
// do Something
},
error: function(xhr) {
// do Something else
}
});
</script>
В вашем отдельном PHP-файле вы можете получить значение из переменной get:
if (isset($_GET['myselectvalue']) && strlen($_GET['myselectvalue']) { // make sure it's populated
$valueFromForm = $_GET['myselectvalue'];
// Execute queries, echo results, etc.
}
Я использовал GET в этом решении, но POST также работал бы.Вам просто нужно изменить type: "get"
на type: "post"
в вызове ajax и $_GET[]
на $_POST[]
в PHP.