javascript - Load same record using paginate in ajax using ajax call and simple page load laravel 4.2 -
i want use same controller function simple page load , load more case using ajax call receive same record time via ajax call
here controller method
public function viewusersbasedonrecentposts() { $page = input::get('page', ''); $users = user::get_most_recent_post_users($page); if(request::ajax()){ sleep(2); $html = view :: make("users.recent_users_view", compact('users'))->render(); $response = array('success'=>true,'html'=>$html); echo json_encode($response,true);die; } return view :: make("users.view_user_basedon_recent_posts", compact('recomendation','users')); }
now here jquery ajax call
$(document).ready(function(){ $(document).on('click', '#loadmorerecentusers', function(){ var page = $(this).attr('page_id'); $.ajax({ type: 'get', url: '<?=route('trendingpostsuser')?>?page='+page, data: {page:page}, beforesend: function(xhr) { $('#loadmoretrrecentusers').html("<div class='pt-sm text-center'><i class='fa fa-circle-o-notch fa-spin fa-2x fa-fw' aria-hidden='true'></i>") },success: function (data) { var obj= json.parse(data); console.log(obj.success); if(obj.success==true || obj.success=='true'){ $('#loadmoretrrecentusers').remove(); $('#databodyrecentusers').append(obj.html); } }, error: function (data) { alert('error occured'); }, }); }); });
now want use same controller method both calls. please me sort out issue.
thanks in advance
wiki
Comments
Post a Comment