本文介绍了如何将JS数组传递给PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想将JS数组转换为PHP数组。我试图将值发送到PHP页面: var seatsReserved = []; function reserve(seat){ seat.setAttribute( class, reserved) ; var hasClass = seat.classList.contains(' 保留'); if (hasClass){ seatsReserved.push( parseInt (seat.innerHTML) )); $ .post(' ../ index.php',{ ' seatsReserved': JSON .stringify( seatReserved)}); console .log(seatsReserved.sort( function (a,b){返回 ab})); } } 然而,当我跑步时 $ seatsReserved = json_decode($ _ POST ['' seatsReserved']); 我收到此错误: 注意:未定义索引:seatsReserved 如何正确地将数组传递给PHP ?解决方案 .post(' ../ index .php',{' seatsReserved': JSON .stringify(seatsReserved)}); console .log(seatsReserved.sort( function (a,b){返回 ab})); } } 然而,当我跑步时 seatsReserved = json_decode( _POST [' seatsReserved']); 我收到此错误: 注意:未定义索引:seatsReserved 如何才能正确地将数组传递给PHP? I would like to convert a JS array to a PHP array. I tried to send the value to the PHP page:var seatsReserved = [];function reserve(seat){seat.setAttribute("class","reserved");var hasClass = seat.classList.contains('reserved');if (hasClass) {seatsReserved.push(parseInt(seat.innerHTML));$.post('../index.php', { 'seatsReserved': JSON.stringify(seatsReserved) });console.log(seatsReserved.sort(function(a, b){return a-b}));}}However, when I run$seatsReserved = json_decode($_POST['seatsReserved']);I get this error:Notice: Undefined index: seatsReservedHow can I correctly pass the array to PHP? 解决方案 .post('../index.php', { 'seatsReserved': JSON.stringify(seatsReserved) });console.log(seatsReserved.sort(function(a, b){return a-b}));}}However, when I runseatsReserved = json_decode(_POST['seatsReserved']);I get this error:Notice: Undefined index: seatsReservedHow can I correctly pass the array to PHP? 这篇关于如何将JS数组传递给PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 06:14