我尝试用 ajax 构建一个小日志。我遵循了一个指南,但他在 php 中构建时没有类和函数。当我尝试通过将其放入类和函数中来重建整个应用程序时,我收到此错误:Undefined index: is_ajax
和我的代码:
<?php
class Login{
public function LoggedIn(){
$is_ajax = $_REQUEST['is_ajax'];
if(isset($is_ajax) && $is_ajax)
{
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if($username == 'demo' && $password == 'demo')
{
echo "success";
}
}
}
}
?>
看法:
public function DoLoginBox() {
$Login = new Login();
//inloggning form-tagg...
return '<p> </p>
<div id="content">
<h1>Login Form</h1>
<form id="form1" name="form1" action="'. $Login ->LoggedIn(). '" method="post">
<p>
<label for="username">Username: </label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="password">Password: </label>
<input type="password" name="password" id="password" />
</p>
<p>
<input type="submit" id="login" name="login" />
</p>
</form>
<div id="message"></div>
</div>';
}