我正在努力提高英语水平
我有一个js看起来通过发送甚至PHP值,然后将这些值存储在php varible我显示我的文件或从中提取
的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>
session.php文件 PHP代码:
<?php
if(isset($_POST["json"])){
$jakson = $_POST["json"];
session_start();
$_SESSION["playlist"][] = $jakson;
}
?>
好了我现在想要一个index2.html或Live index.html收集播放列表会话变量的内容,我创建一个名为recoger.php的测试文件 并将以下内容仅用于查看存储的内容 recoger.php PHP代码:
<?php
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
echo '<br />';
?>
并告诉我以下
PHP代码:
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"}"
}
如何通过jquery ajax实时骨髓每次点击获得这些结果并将值添加到其他ajax会话的变量数组中立即收听该节目
欢迎任何想法帮助,谢谢
答案 0 :(得分:0)
创建ajax调用
...
$.ajax('getSession.php', {...}, function(response){
...
});
...
到你的getSession.php文件,
<?php
// some code
echo json_encode($_SESSION['playlist']) ;
所以在ajax回调体中使用变量响应将是你的$_SESSION['playlist'];