I am trying to use ajax to navigate to a php script in the background so that it performs some commands but the problem is that it is not performing the commands, which tells me that my ajax is either incorrect or I am incorrectly doing something that it is not calling the ajax. Can yo please look at the code and state what I am doing wrong? I known the php script is suppose to navigate to insertQuestion.php does work because if I navigate to that page using the form action, then it performs the commands in that script, but when I try and use ajax to navigate to the script in the background, it just doesn’t do it:
Code:
<form id="QandA" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return myClickHandler()">
....
</form>
function myClickHandler()
{
if (!validation())
return false;
if (!confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" ))
return false;
$.ajax({
url: "insertQuestion.php",
data: $("#QandA").serialize(),
async: false
});
return true;
}
UPDATE:
It is still not navigating to the insertQuestion.php page, also the problem now is that it is not checking for validation and not displaying confirm box in javascript function. Below I have included an update on what current code now looks like:
<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post" onsubmit="return myClickHandler(); return false;">
....
</form>
<script type="text/javascript">
function myClickHandler()
{
if (!validation())
return false;
if (!confirm("Make sure that your details are correct, once you proceed after this stage you would not be able to go back and change any details towards Questions, Options and Answers for your Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" ))
return false;
$.ajax({
url: "insertQuestion.php",
data: $("#QandA").serialize(),
async: false
type: "POST"
});
return true;
}
</script>
use type: “POST” because
.ajax
about submit :
HTML:
JS: