У меня есть файл.js:
$(function(){
var playItem = 0,
title=$('.jp-interface .jp-title'),
jPlayer=$("#jplayer"),
myPlayList = [
{name:"BlackPlant",mp3:"audio/black_plant.mp3",ogg:"audio/black_plant.ogg"},
{name:"Hidden",mp3:"audio/hidden.mp3",ogg:"audio/hidden.ogg"},
{name:"The Separation",mp3:"audio/separation.mp3",ogg:"audio/separation.ogg"}
],
jPlay=function(idx){
if(typeof idx==typeof 0)
jPlayer.jPlayer("setMedia",myPlayList[idx]).jPlayer('play')
if(typeof idx==typeof '')
jPlayer.jPlayer("setMedia",myPlayList[playItem=idx=='next'?(++playItem<myPlayList.length?playItem:0):(--playItem>=0?playItem:myPlayList.length-1)]).jPlayer('play')
title.text(myPlayList[playItem].name)
Cufon.refresh()
}
jPlayer.jPlayer({
ready: function() {
jPlay(playItem)
},
ended:function(){
jPlay('next')
}
})
$(".jp-prev,.jp-next")
.click( function() {
jPlay($(this).is('.jp-next')?'next':'prev')
return false;
})
});
→ База данных, хранящаяся на сервере sql:
name
(nvarchar
)path
(nvarchar
)Мой музыкальный плеер на странице.aspx использует этот скрипт для воспроизведения музыки. Я хочу запросить путь и имя на сервере sql и назначить их файлу myPlayList.js. Есть какой-либо способ сделать это?
Добавьте этот скрипт на страницу Aspx
<script type="text/javascript">
function QueryDB() {
PageMethods.GetServerData(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
var name= result[0];//You will get your name here
var path = result[1];//and your path here
}
function OnFailed(error, userContext, methodName) {
alert(error);
}
</script>
вы также должны добавить
<asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true" EnablePageMethods="true" />
на странице Aspx
Теперь в вашем коде вы должны добавить способ страницы, подобный этому
[System.Web.Services.WebMethod]
public static string[] QueryDB()
{
/* Query your database from here and pass the name and path where I am passing
myName and myPath*/
return new string[] { myName , myPath};
}