Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔4号+;AJAX不起作用_Php_Ajax_Symfony - Fatal编程技术网

Php 拉威尔4号+;AJAX不起作用

Php 拉威尔4号+;AJAX不起作用,php,ajax,symfony,Php,Ajax,Symfony,我对Laravel4非常陌生,我正在尝试测试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/"

我对Laravel4非常陌生,我正在尝试测试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>
和路由器:

Route::get('/', function() {
    return View::make('homepage');
});

Route::post('/ajax/login', 'AuthController@login');
通过单击
登录
它应该会回显“success”,但会抛出以下错误:

ERROR:{
    "error": {
        "type": "Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException",
        "message": "",
        "file": "C:\\xampp\\htdocs\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
        "line":1429
    }
}

这有什么不对?

在AJAX调用中,更改:

  url: "laravel/ajax/login",
致:

您的路线正在收听
ajax/login
而不是
laravel/ajax/login


阅读更多有关路线的信息。

是的,现在它可以工作了,实际上现在还有另一个问题,谢谢你的帮助answering@user2002495你可以随时在这里提交,我们很乐意提供帮助。我可以知道是谁否决了我的问题吗?即使它解决了问题?我又一次否决了,我不知道否决票是怎么回事,在解决了url问题后,控制器函数登录回显成功吗?@John:是的,已经解决了,感谢您回答您尝试使用ajax登录时出现的验证错误。参考这篇文章是好的
  url: "laravel/ajax/login",
  url: "ajax/login",