1

我正在创建 phonegap 登录表单,当我单击登录时我使用 laravel 作为后端代码我有这个错误消息 php 代码

Route::secure('POST', 'login', function()
{
    $remember = Input::get('remember');
    $credentials = array(
        'username' => Input::get('username'), 
        'password' => Input::get('password'),
        'remember' => !empty($remember) ? $remember : null
    );

    if (Auth::attempt( $credentials ))
    {
        return Response::json('Logged in');
        //return Redirect::to_action('user@index'); you'd use this if it's not AJAX request
    }else{
        return Response::json('Error logging in', 400);
        /*return Redirect::to_action('home@login')
        -> with_input('only', array('new_username')) 
        -> with('login_errors', true);*/
    }
});

html

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
       <!-- <div class="app">
            <h1>Test Zone</h1>
            <div class="test-zone" id="test-zone">

            </div>
        </div>-->
        <form class="form-vertical" id="login" method="POST" action="http://localhost:8888/laravel/public/login" accept-charset="UTF-8">
            <input required="true" type="text" name="username" id="username">
                <br/>
            <input required="true" type="password" name="password" id="password">
                <br/>
            <input id="remember" type="checkbox" name="remember" value="1">Remember me</label>
            <input id="loginBtn" type="submit" value="Login">
        </form>

        <script>
            $(function() {
              $('#loginBtn').click(function(e){
                                   e.preventDefault();
                                   $.ajax({
                                          url: 'login',
                                          type: 'post',
                                          dataType: 'json',
                                          data: $('form#login').serialize(),
                                          success: function(data) {
                                          alert("Logged in"); // <- this would have to be your own way of showing that user is logged in
                                          },
                                          error: function (xhr, ajaxOptions, thrownError) {
                                          alert(xhr.responseText); // <- same here, your own div, p, span, whatever you wish to use
                                          }
                                          });
                                   return false;
                                   });
              });
            </script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
       <!-- <script type="text/javascript">
            app.initialize();
        </script>-->
    </body>
</html>

错误

    Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
open: /Applications/MAMP/htdocs/laravel/bootstrap/compiled.php
            $value = new Response($value);
        }
        return $value->prepare($request);
    }
    protected function handleRoutingException(\Exception $e)
    {
        if ($e instanceof ResourceNotFoundException) {
            throw new NotFoundHttpException($e->getMessage());
        } elseif ($e instanceof MethodNotAllowedException) {
            $allowed = $e->getAllowedMethods();
Server/Request Data
HTTP_HOST   localhost:8888
HTTP_CONNECTION keep-alive
HTTP_CACHE_CONTROL  max-age=0
HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_USER_AGENT Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36
HTTP_ACCEPT_ENCODING    gzip,deflate,sdch
HTTP_ACCEPT_LANGUAGE    en-US,en;q=0.8
HTTP_COOKIE SQLiteManager_currentLangue=2; laravel_session=fd0693d4479cd76b082948740ce3903a
PATH    /usr/bin:/bin:/usr/sbin:/sbin
SERVER_SIGNATURE    
SERVER_SOFTWARE Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8x DAV/2 PHP/5.4.10
SERVER_NAME localhost
SERVER_ADDR ::1
SERVER_PORT 8888
REMOTE_ADDR ::1
DOCUMENT_ROOT   /Applications/MAMP/htdocs
SERVER_ADMIN    you@example.com
SCRIPT_FILENAME /Applications/MAMP/htdocs/laravel/public/index.php
REMOTE_PORT 53229
GATEWAY_INTERFACE   CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD  GET
QUERY_STRING    
REQUEST_URI /laravel/public/
SCRIPT_NAME /laravel/public/index.php
PHP_SELF    /laravel/public/index.php
REQUEST_TIME_FLOAT  1379301213.89
REQUEST_TIME    1379301213
argv    Array ( )
argc    0
GET Data
empty
POST Data
empty
Files
empty
Cookies
SQLiteManager_currentLangue 2
laravel_session fd0693d4479cd76b082948740ce3903a
Session
_sf2_attributes Array ( [_token] => 5UIH1CsFXEpY5BN1lTmIhPNUMlPOX6DcilpYixUs )
_sf2_flashes    Array ( )
_sf2_meta   Array ( [u] => 1379301213 [c] => 1379301110 [l] => 7200 )
4

2 回答 2

0

改变

Route::secure('POST', 'login', function()

Route::post('login', array('https', function()

所以你的功能现在看起来像这样

Route::post('login', array('https', function()
{
    $remember = Input::get('remember');
    $credentials = array(
        'username' => Input::get('username'), 
        'password' => Input::get('password'),
        'remember' => !empty($remember) ? $remember : null
    );

    if (Auth::attempt( $credentials ))
    {
        return Response::json('Logged in');
        //return Redirect::to_action('user@index'); you'd use this if it's not AJAX request
    }else{
        return Response::json('Error logging in', 400);
        /*return Redirect::to_action('home@login')
        -> with_input('only', array('new_username')) 
        -> with('login_errors', true);*/
    }
}));   // <- Note the EXTRA ")" at the end here

确保将额外的“)”放在函数的末尾

如果您不使用“https” - 使用此功能

Route::post('login', function()
{
    $remember = Input::get('remember');
    $credentials = array(
        'username' => Input::get('username'), 
        'password' => Input::get('password'),
        'remember' => !empty($remember) ? $remember : null
    );

    if (Auth::attempt( $credentials ))
    {
        return Response::json('Logged in');
        //return Redirect::to_action('user@index'); you'd use this if it's not AJAX request
    }else{
        return Response::json('Error logging in', 400);
        /*return Redirect::to_action('home@login')
        -> with_input('only', array('new_username')) 
        -> with('login_errors', true);*/
    }
});
于 2013-09-16T03:04:07.207 回答
0

我希望您从Maxoffsky.com中获取了这个示例。你有没有注意到它。我们需要一个 https 服务器才能执行此操作。我也面临类似的问题,但使用 https 服务器处理。

于 2014-04-30T03:32:06.863 回答