2

私は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>
4

2 に答える 2

0

type: "POST" を使用する理由

type String Default: 'GET' 作成するリクエストのタイプ (「POST」または「GET」)。デフォルトは「GET」です。注: PUT や DELETE などの他の HTTP 要求メソッドもここで使用できますが、すべてのブラウザーでサポートされているわけではありません。

.ajax

$.ajax({
            url: "insertQuestion.php",
            data: $("#QandA").serialize(),
            async: false,
            type: "POST"
        });

送信について : HTML:

<form id="QandA">
...
</form>

JS:

$(function() {
myClickHandler=function(e)
    {
        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;
    };



$('#QandA').submit(myClickHandler);



});
于 2012-11-01T03:54:03.613 に答える
-1

htmlentities() を削除してください

<form id="QandA" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return myClickHandler()">

....

</form>

または、「return false;」を追加して別の方法を試してください。送信する。

<form id="QandA" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return myClickHandler(); return false;">

....

</form>
于 2012-11-01T03:31:11.787 に答える