私はajaxを使用してバックグラウンドでphpスクリプトに移動し、いくつかのコマンドを実行しようとしていますが、問題はコマンドが実行されていないことです。これは、ajaxが正しくないか、間違って何かをしていることを示しています。 ajaxを呼び出していません。コードを見て、私が間違っていることを述べてもらえますか?フォームアクションを使用してそのページに移動すると、そのスクリプトのコマンドが実行されるため、phpスクリプトは機能することを想定してinsertQuestion.php
いますが、ajaxを使用してバックグラウンドでスクリプトに移動しようとすると、ただそれをしません:
コード:
<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;
}
アップデート:
それでもinsertQuestion.phpページに移動していません。また、問題は、検証をチェックしておらず、javascript関数で確認ボックスを表示していないことです。以下に、現在のコードが現在どのようになっているのかについての更新を含めました。
<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>