I have {% framework extras turbo %} in my header-links partial. I’ve tried removing turbo and extras, but I have no idea what is wrong. I can even change the data-request to a non-existent function, and nothing changes - no error.
Thank @apinard for the reply. Are you sure the anchor tag won’t work without a url? It responds the same as the button.
I am trying to get my site dialed in for front end users with register, login, logout, and forgot password. I am using the rainlab user plugin. The example code on the plugin page for logout doesn’t work.
Oddly enough, this example code doesn’t have a URL either.
I was able to create my own logout route which if fine, but I really want to figure out what is wrong with their example code, so I built this AJAX test.
@apinard I removed the [Session] component and replaced my custom signout link with <a data-request="onLogout" data-request-data="redirect: '/good-bye'">Sign out</a>
Session is in the page, not the layout. Maybe I should put it in the layout? Wondering what the difference is between putting it in each individual page, the layout, or the nav-links partial in the layout.
The user is there because the signout link is displayed (actually both are displaying right now). My custom link works great, but again, trying to figure out what is going on with AJAX.
My signout link is in a route of a plugin I built.
Route::group(['middleware' => ['web']], function () {
Route::get('signout', function (Request $request) {
$user = Auth::getUser();
Auth::logout();
// I am not exactly sure what this does
// $this->guard()->logout();
// This doesn't seem neccessary - but what does it do beyond auth::logout?
// $request->session()->invalidate();
if ($user) {
Event::fire('rainlab.user.logout', [$user]);
}
// $url = post('redirect', Request::fullUrl());
Flash::success(Lang::get('rainlab.user::lang.session.logout'));
return redirect('/');
// return Redirect::to($url);
})->name('signout');
});
There is a lot going on here so its see exactly where your issue is. The best thing to do in these cases is to isolate the issue. Try this and it should work.
##
title = "Test AJAX"
layout = "default"
url = "/testajax"
==
<?
function onDoSomething() {
return 'done';
}
?>
==
<button type="button" data-request="onDoSomething" class="btn btn-default">
Do Something
</button>