我对 Laravel 4 很陌生,我正在尝试测试 AJAX 请求。
在我的script.js
我有这个:
(function() {
$("#login-submit").click(function(e) {
e.preventDefault();
return $.ajax({
type: "POST",
url: "laravel/ajax/login", //i put my public in "localhost/laravel/public/"
cache: false,
data: 'email:' + $("#email").val(),
success: function(data) {
return alert(data);
},
error: function(response) {
return alert("ERROR:" + response.responseText);
}
});
});
}).call(this);
这是从此 html 文件中调用的:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form>
<label for="email">Email: </label>
<input type="text" id="email" />
<label for="email">Password: </label>
<input type="password" id="password" />
<button id="login-submit">Log In</button>
</form>
<script type="text/javascript" src="assets/js/jquery/jquery.custom.js"></script>
<script type="text/javascript" src="assets/js/script.js"></script>
</body>
</html>
控制器类:
class AuthController extends BaseController
{
public function login()
{
echo 'success';
}
}
和路由器:
Route::get('/', function() {
return View::make('homepage');
});
Route::post('/ajax/login', 'AuthController@login');
通过单击Log In
它应该回显“成功”,但它会引发此错误:
ERROR:{
"error": {
"type": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
"message": "",
"file": "C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
"line":1429
}
}
这有什么问题?