mardi 15 mars 2016

Username Available Check Using Laravel 5 in Ajax

Username available check in my register form if I am enter the username after loader.gif is loading but I am not getting the result for username available or not.. give me any suggestion

This is My Controller:

public function name()
{
    $username = Input::get('username');
    $users = DB::table('user')
               ->where('username', $username)
               ->first(); 
    if ( $users !== null )
    {
        return true;
    }
         return false;
         return view('test/username');
}

This is My Route:

Route::get('test/name', 'PageController@name');

This is My Blade Template Ajax:

  <script type="text/javascript">

     $(document).ready(function(){
        $("#username").change(function(){
             $("#message").html("<img src='../images/loader.gif' /> checking...");


        var username=$("#username").val();
          //alert(username);
          $.ajax({
                type:"post",
                 dataType: "json",
                url :"{{URL::to('test/name') }}",
               data: {username: username},
                    success:function(data){
                    if(data==0){
                        $("#message").html("<img src='../images/yes.png' /> Username available");
                    }
                    else{
                        $("#message").html("<img src='cross.png' /> Username already taken");
                    }
                }
             });

        });

     });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire