So I have been looking at all possible answers so far on Stackoverflow. But no matter how I try, I can't get this to work.
I'm trying to set a sessionvariable according to a clicked linked.
this can be 'grid' or 'list'
I can change the class, and the view of the corresponding div. However, my $.post call to php is not passing the variable ( im assuming this, since nothing happens ) or my php call is wrong.
Here's my code:
HTML
<li class="display-control-list-item" > <a href="javascript: void(0)" class="js-set-display list" id="list" > Listview </a> </li>
<li class="display-control-list-item" > <a href="javascript: void(0)" class="js-set-display grid" id="grid" > Gridview </a> </li>
JQUERY
function set_display_type( type ) {
if ( type == 'grid' ) {
$( '.js-set-display.list' ).removeClass( 'active' );
$( '.js-set-display.grid' ).addClass( 'active' );
$( '.content-inner' ).attr({ 'class' : 'container content-inner gridview' });
var view = 'gridview';
$.post( 'library/fx.behaviour.php' , { setdisplay: view });
}
if ( type == 'list' ) {
$( '.js-set-display.grid' ).removeClass( 'active' );
$( '.js-set-display.list' ).addClass( 'active' );
$( '.content-inner' ).attr({ 'class' : 'container content-inner listview' });
var view = 'listview';
$.post( 'library/fx.behaviour.php' , { setdisplay: view });
}
}
and my PHP in fx.behaviour.php
$_SESSION[ 'display' ] = 'listview'; // set default
if ( $_POST[ 'setdisplay' ] != '' ) {
$view = $_POST[ 'setdisplay' ];
$_SESSION[ 'display' ] = $view;
}
In short: the sessionvariable won't update after clicking the url and passing the value through jquery to php.
jQuery, remember if thephpfile is on a folder outside youjQueryexecution file you need to add../at the beginning of yourphpfile path atjQuery$.post()definition