$('.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'];
?>
回显结果是旧值,因为未设置$_POST
个变量
如何获取新值,在javascript代码中设置?
答案 0 :(得分:1)
你在请求中犯了一个错误,使用:method: "post"
而不是type: "post"
,所以难怪post var没有设置:)
$('.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();
}
});
});
希望这会解决它;)
干杯!
答案 1 :(得分:0)
当你包含params.php时,它会将值重置回两个else
块中的if
条件。