Thursday, February 1, 2018

Laravel request()->ajax() triggering on browser back button - development

Laravel request()->ajax() triggering on browser back button

Inside my controller I have this function for the route /backups

public function index()
{
    $backups = AppBackup::all();

    if(request()->ajax()) {
        return $backups;
    }

    return view('backups.index', compact('backups'));
}

My idea was that if I have my javascript ask for the data then return json if not return html.

This works fine, except when pressing the browser back button to go from lets say /backups/1 to /backups it shows the json.

Is there another function I can use that will only respond to ajax calls from my code and not the browsers?



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-request-ajax-triggering-on-browser-back-button/
via Lzo Media

No comments:

Post a Comment