jeudi 26 octobre 2017

Return data from controller to ajax laravel

I want to show notifications when new row inserted.I've achieved it through the below code, Ajax

<script>

    var old_count = 0;
    var i=0;
    setInterval(function(){    
    $.ajax({

    url : "shownotify",
    success : function(data){
    if (data > old_count) 
    { 
        if (i == 0)
        {old_count = data;} 
        else{
        $('#notify').html("New user");
        old_count = data;
        }
    } i=1;
 }
});
},1000);                                
        </script>

Now I want to show the count of new users which I returned from controller,

public function shownotify()
{
     $action=DB::table('users')->where('admin_action_at', 'null')->count();
     $data=Move::count();

    return compact('action', 'data');

}

How do I get it in ajax function?Can anybody help?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yPJdqr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire