Forum Moderators: open
$(document).ready(function() {
$('select[name="CategoryID"]').change(function() {
var SelectedCategoryID = $('select[name="CategoryID"] option:selected').val();
$.ajax({
method: "POST",
url: 'phpProcessor.php',
data: { CategoryID: "SelectedCategoryID" },
cache: false
}).done(function(data) {
$('select[name="SubCategoryID"]').html(data);
})
});
});
PHP processor script
$_POST['CategoryID'] = trim($_POST['CategoryID']);
// Validation before using
if (ctype_digit($_POST['CategoryID'])) {// Fails as POST array is not set
print '<option>response has been validated</option>';
}
// This works and updates/changes the expected sub category select
print '<option value="55" selected="true">input failed validation</option>
<option value="955">input is not valid</option>';
var_dump($_POST);
data: { CategoryID: "SelectedCategoryID" }, var_dump( file_get_contents('php://input') ); <form method="POST" action="phpProcessor.php"><input name="CategoryID" value="375" /><button type="submit">test</button></form>
1. your browser's developer console (usually access through F12 or Ctrl+Shift+I) network tab - does request to 'phpProcessor.php' goes through and carries neccesary data (request details -> headers -> scroll down, there should be Form Data section with "CategoryID: ...".