post

Sending a JavaScript array to PHP via POST

泪湿孤枕 提交于 2020-11-29 07:38:44
问题 I am trying to send a JavaScript array to a PHP file via POST. JS: var songlist = ['song1', 'song2', 'song3']; var sendData = function(){ var data = songList.join(',') $.post('test.php', {data: data}).always(function() { window.location = 'test.php'; }); } sendData(); test.php: <?php $songData = $_POST['data']; $songData = explode(',', $songData); print_r(array_values($songData)); ?> when sendData(); directs me to test.php I get: Notice: Undefined index: data Why doesn't the data variable

Sending a JavaScript array to PHP via POST

女生的网名这么多〃 提交于 2020-11-29 07:35:00
问题 I am trying to send a JavaScript array to a PHP file via POST. JS: var songlist = ['song1', 'song2', 'song3']; var sendData = function(){ var data = songList.join(',') $.post('test.php', {data: data}).always(function() { window.location = 'test.php'; }); } sendData(); test.php: <?php $songData = $_POST['data']; $songData = explode(',', $songData); print_r(array_values($songData)); ?> when sendData(); directs me to test.php I get: Notice: Undefined index: data Why doesn't the data variable

Sending a JavaScript array to PHP via POST

瘦欲@ 提交于 2020-11-29 07:34:19
问题 I am trying to send a JavaScript array to a PHP file via POST. JS: var songlist = ['song1', 'song2', 'song3']; var sendData = function(){ var data = songList.join(',') $.post('test.php', {data: data}).always(function() { window.location = 'test.php'; }); } sendData(); test.php: <?php $songData = $_POST['data']; $songData = explode(',', $songData); print_r(array_values($songData)); ?> when sendData(); directs me to test.php I get: Notice: Undefined index: data Why doesn't the data variable