我試圖上傳和播放歌曲與HTML5。我正在使用JavaScript將文件上傳到服務器和jPlayer播放歌曲,但我遇到了這個插件的問題。上傳和播放歌曲
這是我的代碼:
$(document).ready(function() {
$(this)
.bind("dragenter", function(event) {
return false;
})
.bind("dragover", function(event) {
return false;
})
.bind("drop", function(event) {
var file = event.originalEvent.dataTransfer.files[0];
event.preventDefault();
$("#state").html("Loading...");
$.ajax({
url: 'upload.php',
async: true,
type: 'POST',
contentType: 'multipart/form-data',
processData: false,
data: file,
success: function(data) {
$("#state").html("Ready!");
$("#player").jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
oga: file.name
}).jPlayer("play");
},
supplied: "oga"
});
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-File-Name", file.name);
xhr.setRequestHeader("Cache-Control", "no-cache");
}
});
});
});
該文件上傳到服務器上,但jPlayer不打它,我想不通爲什麼...
@vigrond:是我可以! ;)
<html id = "homepage">
<head>
<title>Echo</title>
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type = "text/javascript" src = "jquery.jplayer.min.js"></script>
<script type = "text/javascript" src = "upload.js"></script>
</head>
<body bgcolor = "black">
<div style = "margin: 0 auto; text-align: center">
<h1 style = "margin-top: 100px; color: white">Drag and drop a song...</h1>
<h2 id = "state" style = "color: white"></h2>
</div>
<div id = "player"></div>
</body>
</html>
你能提供你的HTML嗎?有幾個步驟需要讓jPlayer正常運行,並且正確的HTML元素就是其中之一。您可能還想嘗試設置errorAlerts:true和warningAlerts:true。這通常會通過警報對話框爲您提供有關正在進行的操作的具體信息。 – Vigrond
已編輯! 7更多去... –