0
$('.folder').on('contextmenu', function(ev){
    ev.preventDefault();
    var a = $(this).attr('data-id');
    var b = $(this).text();
    $('.marked').removeClass('marked');
    var c = $('#path').html();
    var d = '<span class="spant" data-id=' + a + '>' + b + '</span>';
    var e = c + d;
    $.ajax({
        url: 'params.php',
        type: 'post',
        data: {
            'path': e,
            'par': a
            },
        success: function() {
            location.reload();
        }
    });

});

params.php

session_start();
if(isset($_POST['path'])) {
    $_SESSION['path'] = $_POST['path'];
}
else{
    $_SESSION['path'] = '<span class="spant" data-id=0>HOME</span>';
}

if(isset($_POST['par'])) {
    $_SESSION['par'] = $_POST['par'];
}
else{
    $_SESSION['par'] = 0;
}

admin.php

<?php
include ("params.php");
echo $_SESSION['path'];
echo $_SESSION['par'];
?>

Result of echoing is old values, as $_POST variables are not set.
How can I get new values, set in javascript code ?

1

2 Answers 2

1

You made a mistake in the request, use: method: "post" instead of type: "post", so no wonder the post var's aren't set :)

$('.folder').on('contextmenu', function(ev){
    ev.preventDefault();
    var a = $(this).attr('data-id');
    var b = $(this).text();
    $('.marked').removeClass('marked');
    var c = $('#path').html();
    var d = '<span class="spant" data-id=' + a + '>' + b + '</span>';
    var e = c + d;
    $.ajax({
        url: 'params.php',
        method: 'POST',
        data: {
            'path': e,
            'par': a
            },
        success: function() {
            location.reload();
        }
    });

});

Hope this will fix it ;)

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

0

When you include params.php it's resetting the values back to the else conditions in your two if blocks.

2 Comments

I tried to address ajax code to admin.php and move if code from params.php to admin.php - the same result.
Have you logged $_POST to see what's in it? Maybe also call session_start() directly in admin.php (instead of including params.php) to make sure it's not that code? At the moment, if admin.php is every called without $_POST values, it's going to revert to your else values.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.