我没有做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;
}
}