传递所选DIV的ID到下一个PHP页面,没有表单或URL变量


Passing ID of selected DIV to next PHP page without form or URL variables

我在javascript中有一些变量

window.location.href = 'chosendivs.php?Selected=' + qs;

其中qs是一个不同div ID的数组,它传递到URL中的下一个页面,如下所示:

chosendivs.php?Selected=d41%2Cd42

我不喜欢通过URL传递这些div的想法,除了使用表单来发布它们之外,还有其他方法吗?

您可以使用POST发送ajax请求

qs= [];
qs[0] = 'id1';
qs[1] = 'id2';
$.ajax({
   type: "POST",
   data: {qs:qs},
   url: "http://localhost/{web_server}/chosendivs.php",
});

,如果在chosendivs.php处执行var_dump($_POST),则数组将显示为JSON格式。可以使用json_decode在PHP端操作数据