I want to call a php function after an event listener within the same document. So I have PHP, HTML and all in the same file. I looked in this thread: using jquery $.ajax to call a PHP function. However in the url it is a separate file.
document.getElementById("categoryone").addEventListener("change", function(event)
{
$.ajax({ url: 'pageTwo.php',
data: {action: 'test'},
type: 'post',
success: function(output) {
alert(output);
}
});
});
And my PHP looks like this:
if(isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
switch($action) {
case 'test' : test();break;
}
}