I'm completely new to the concept of AJAX, but discovered that it's needed in order to accomplish what I'm setting out to do. Basically I just need need it to set the php variable $submitted equal to true whenever a post happens, which in turn runs a query to my database. For some reason, though this code makes sense to me, it doesn't seem like it's making it to the ajax file, even though I'm getting the "success" alert and I don't have console errors. Anything glaringly wrong?
<form action="call.php" method="post">
<input class="oomText" type="text" name="accountName" placeholder="Account Name"><br>
<input class="oomButton submit" type="submit" name="submit" value="submit">
<script>
$(document).ready(function(){
$('.oomButton.submit').click(function(){
var clickBtnValue = $(this).val();
var ajaxurl = '/ajax.php',
data = {'action': clickBtnValue};
$.post(ajaxurl, data, function (response) {
alert("Account Created");
});
});
});
</script>
</form>
AJAX.PHP
<?php
if (isset($_POST['action'])) {
switch ($_POST['action']) {
case 'submit':
submit();
break;
}
}
function submit() {
$submitted = true;
exit;
}
?>