在laravel中应用ajax - javascript

我想在laravel 4.2中应用ajax。我想重定向到页面而不重新加载它。我已经尝试过使用window.loaction.hrefwindow.loaction.assign了,但是它不起作用。这是我的文件

Route.php

        //login+logout+auth
    Route::get('login','authenticationController@create')->before('guest');
    Route::get('logout','authenticationController@destroy');
    Route::get('create_user_view',array('as'=>'create_user','uses'=>'authenticationController@create_user'));
    Route::post('create_user_store',array('as'=>'store_user','uses'=>'authenticationController@store_user'));

Route::resource('authentication','authenticationController');

controller.php

public function store()
{
    // return Response::json(array('msg'=>'true'),200);exit;    
    $input=Input::all();
    $user=User::where('email',$input['email'])->pluck('id');

    $user_priviledge=Priviledge::where('user_id', $user)->pluck('user_authority');
    //var_dump($user_priviledge);die;

    if($user_priviledge==1)
    {   
        $attempt=Auth::attempt([
        'email'=>$input['email'],
        'password'=>$input['password']

    ]);
        //var_dump($input['password']);die;
        //var_dump($attempt);exit;
        if($attempt)
        {   

            return 'true';
        }else{
            return Redirect::intended('login');
            }
    }else{
        return Redirect::intended('login')->with('message', 'User Disabled');;
    }
}

光头

    @extends('app')

@section('content')
<!--login form-->
<div class="login">
    {{Form::open(array('url'=>route('authentication.store')))}}
    <div>
        <h2>Sign in to your account</h2>
        <table>
            <tr>
                <th class="table">{{ Form::text('email', Input::old('E-mail'),  array('id'=>'email','placeholder'=>'E-Mail','class'=>'placeholder')) }}</th>
                <th>{{$errors->first('email')}}</th>
            </tr>
            <tr>
                <th class="table">{{ Form::password('password', array('id'=>'password','placeholder'=>'Your Password','class'=>'placeholder')) }}</th>
                <th class="table">{{$errors->first('password')}}</th>
            </tr>
            <tr>
                <div>
                    <th class="table">{{Form::button('Login',array('class' => 'btn-login','onclick'=>'myfunc()'))}}</th><!--login button code-->
                </div>

            </tr>
            <tr>
                <th class="table"><!--reset button code-->
                    <div class="reset">
                        <a href="">I can't access my account</a>
                    </div>
                </th>
            </tr>
            <tr>
                <th class="table"><!--create button code-->
                    <div class="create-account">
                        <a href="{{route('create_user')}}">Create Account</a>
                    </div>
                </th>
            </tr>
        </table>
    </div>  
</div>
<script>
    function myfunc(){

        var email =document.getElementById("email").value;
        var password =document.getElementById("password").value;

        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                //alert("hello");
                // var data = xmlhttp.responseText;

                // console.log(xmlhttp.respons?eText);
                var text = Json.parse(xmlhttp.responseText);
                console.log(text);
                if(xmlhttp.responseText =='true'){

                    window.location.assign('http://localhost/votting-system/public/home');
                    //alert("hello");
                }
            }
        }
        xmlhttp.open("POST",'http://localhost/votting-system/public/authentication',true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("email=" +email+ "&password=" +password);
    }
</script>
@stop

现在的问题是,当我单击提交按钮时,它应该已经重定向到主页所在的页面,但是当我单击登录按钮时,它什么都不做,那么当我重新加载该页面时它将显示主页。这意味着它正在被记录进入,但是页面没有重新加载就不会重定向到主页。

javascript参考方案

您想尝试href对象的location属性

window.location.href='http://localhost/votting-system/public/home';

将简单的javascript代码转换为c# - javascript

昨天我在这里问了一个问题。使用javascript和html解决方案很简单前一阵子我打算什么是操纵html来执行javascript中的任务但是我改变了主意,将javascript代码重写为c#这是输入<Abstract> <Heading>Abstract</Heading> <Para TextBreak=�…

如果复选框切换复选框已选中,则在切换div中输入必填字段 - javascript

我使用脚本用JavaScript切换了一些div。如果要选中复选框以显示toogle div,我想在toogle div中设置一些“必填”输入字段。有人能弄清楚吗?那是工作吗?function show(id) { if(document.getElementById) { var mydiv = document.getElementById(id); m…

从其他文件夹访问母版页 - javascript

我认为这应该很容易但不确定如何解决。我在主文件夹中有一个名为01.aspx的页面01.aspx页应该继承products.master项目根目录存在于products.master中像下面的照片:我使用波纹管代码,但没有任何工作的JavaScript,图像和...01.aspx<%@ Page Title="" Language=&…

打印二维阵列 - javascript

我正在尝试打印子元素。在this example之后。怎么做?。$myarray = array("DO"=>array('IDEAS','BRANDS','CREATIVE','CAMPAIGNS'), "JOCKEY"=>a…

单击按钮时输入框值消失 - javascript

我刚开始使用JQuery for asp.net core mvc。我有一个页面的一部分,其中包含链接到主要主题的项目列表。当在列表项之一上单击“编辑”按钮时,将显示一个隐藏部分(字段集),并用该列表项的值填充。页面上的其他输入被禁用,用户可以编辑该项目。一切正常。但是,完成编辑后,用户单击“提交”按钮(在先前隐藏的字段集中),其想法是通过ajax提交编辑的…