Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以使用jquery会话变量获取数据吗?调用php_Php_Javascript_Jquery_Ajax_Json - Fatal编程技术网

可以使用jquery会话变量获取数据吗?调用php

可以使用jquery会话变量获取数据吗?调用php,php,javascript,jquery,ajax,json,Php,Javascript,Jquery,Ajax,Json,我正在努力提高我的英语水平 我有一个js外观,通过post甚至php值发送​​然后存储这些值​​在php变量中,我显示了我的文件或它们的摘录 index.html HTML代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" /> <script type="text/javascript" src="http://a

我正在努力提高我的英语水平

我有一个js外观,通过post甚至php值发送​​然后存储这些值​​在php变量中,我显示了我的文件或它们的摘录

index.html HTML代码:

<!DOCTYPE HTML>
<html>
<head>
   <meta http-equiv="content-type" content="text/html" />
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
    <script>
$(document).ready(function () {
     $('.add-music').click(function () {
         var songNew = JSON.stringify({
             title: $(this).attr('data-title'),
             artist: $(this).attr('data-artist'),
             mp3: $(this).attr('href')
         });
         var songIE = {json:songNew};
         $.ajax({
             type: 'POST',
             data: songIE,
             datatype: 'json',
             url: 'session.php',
             async: true,
             cache: false
         });
     });
 });
    </script>
</head>
<body>
        <b class="add-music" data-title="chika" data-artist="comppac" href="audios/song-little.mp3">Add to List</b>
        <b class="download-music" href="audios/song-little.mp3">Download</b>

        <b class="add-music" data-title="mediana" data-artist="comppam" href="audios/song-med.mp3">Add to List</b>
        <b class="download-music" href="audios/song-middle.mp3">Download</b>

        <b class="add-music" data-title="grande" data-artist="comppag" href="audios/song-big.mp3">Add to List</b>
        <b class="download-music" href="audios/song-big.mp3">Download</b>
</body>
</html>
我如何通过jquery ajax live获得这些结果,并在每次单击后立即向其他ajax会话的变量数组中添加一个值来收听本节目

欢迎任何想法帮助,谢谢创建ajax调用

<?php 
// some code
echo json_encode($_SESSION['playlist']) ; 
到getSession.php文件,该文件


要将它们放到JS中,您需要一个
成功:函数(m){//what To do here}
,在PHP中,在从ajax请求发回数组之前,按照您的意愿制作数组并使用
json\u encode
<?php 
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
echo '<br />';
 ?> 
array(1) {
  ["playlist"]=>
  array(4) {
    [0]=>
    string(111) "{"title":"emo","artist":"a href=","mp3":"/audios/01%20-%20Survie.mp3"}"
    [1]=>
    string(158) "{"title":"Las Voces de L@s del Bosque","artist":"","mp3":"/audios/La%20voces%20de%20l%40s%20del%20Bosque%20copy.mp3"}"
    [2]=>
    string(143) "{"title":"radio novela waO1","artist":"","mp3":"/audios/radionovela%20wagia%20final.mp3"}"
    [3]=>
    string(174) "{"title":"o a La Comunicación","artist":"","mp3":"/audios/Cun%CC%83aunicacion.mp3"}"
  }
...
$.ajax('getSession.php', {...}, function(response){
...
});
...
<?php 
// some code
echo json_encode($_SESSION['playlist']) ;