1

私はあまり作業していませんAJAXが、私がやろうとしているのは、ユーザーがデータを入力し、[送信] をクリックして、結果のページを更新する代わりに、結果が表示されるフォームを作成するmodal windowことです。私の理解では、AJAXこれを機能させるには使用する必要があります。

以下は、これまでの私のコードです。最初に呼び出しを機能させようとしているだけであることに注意してくださいAJAX。後でモーダルウィンドウについて心配します。

現時点では、送信ボタンを押したときに達成されるのは、ページがフォームアクションを実行しtestauthcall.php、結果が空白のページにある場所に移動することだけです (ページの読み込みを強制終了するはずecho'dだと思っていましたか?)。return false;

HTMLファイル: testauth.php

<form id="myForm" action="testauthcall.php" method="post"> 
    Username: <input type="text" name="user" /> 
    Password: <input type="text" name="pass" />
    <input type="submit" value="Test Authentication" /> 
</form>

Javascriptファイル: testauth.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 

<script type="text/javascript"> 

var frm = $('#myForm');
frm.submit(function () {
    $.ajax({
        type: frm.attr('method'),
        url: frm.attr('action'),
        data: frm.serialize(),
        success: function (data) {
            alert('ok');
        }
    });
    return false;
});

<script>

PHPファイル: testauthcall.php

require_once('variables/radius.class.php');

    if ((isset($_POST['user'])) && ('' != trim($_POST['user'])))
    {
        $radius = new Radius('xxx.xxx.xxx.xx', 'xxxxxxxxxx');

        if ($radius->AccessRequest($_POST['user'], $_POST['pass']))
        {
            $authresult = "<strong>Authentication accepted.</strong>";
            echo $authresult;
        }
        else
        {
            $authresult = "<strong>Authentication rejected.</strong>";
            echo $authresult;
        }
    }
4

1 に答える 1