jquery替换内容时页面刷新的奇怪行为


jquery weird behavior of page refresh when i replace content

我有一个带flash播放器的网站。

此代码为我提供存储在player_codes.hp:中的flash播放器

<script language="javascript" type="text/javascript" src="songs_related/flashmp3player/swfobject.js" ></script>
<!-- Div that contains player. -->
<div id="player">
    <h1>No flash player!</h1>
    <p>It looks like you don't have flash player installed. <a href="http://www.macromedia.com/go/getflashplayer" >Click here</a> to go to Macromedia download page.</p>
</div>
<!-- Script that embeds player. -->
<script language="javascript" type="text/javascript">
    var so = new SWFObject("songs_related/flashmp3player/flashmp3player.swf", "player", "290", "247", "9"); // Location of swf file. You can change player width and height here (using pixels or percents).
    so.addParam("quality", "high");
    so.addVariable("content_path","songs_related/uploads"); // Location of a folder with mp3 files (relative to php script).
    so.addVariable("color_path","songs_related/flashmp3player/default.xml"); // Location of xml file with color settings.
    so.addVariable("script_path","songs_related/flashmp3player/flashmp3player.php");     
    // Location of php script.
    so.write("player"); 
</script>

这就是我如何包括播放器后端

<div id="main_music_player_for_the_site">
    <?php include_once('player_codes.php'); ?>
</div>

如果你转到这里的链接,并在列表中的任何歌曲上按播放,就会发生以下情况:

  1. 我向后台发送请求并设置歌曲
  2. 我得到了确认
  3. 我从player_codes.php加载播放器(如上所述)

但当第3步发生时,它会刷新并被卡住

它不应该引用它在我的本地主机中也不刷新。

这是我做这项工作的JS(在步骤2中得到响应后调用)

function callBackForLoadSong(data)
{
    //alert(data);
    if(data == "failed")
    {
        alert("Song requres you to login. Its easy to create an account! We will take you to the login page after you press ok");
        window.location.replace(REDIRECT);
    }
    else
    {
        //alert("s");
        $("#main_music_player_for_the_site").text("refreshing player...");
        $("#main_music_player_for_the_site").load("player_codes.php");
    }
}

困扰我的主要问题是为什么页面被刷新???并且被卡住

每个播放按钮都有相同的HREF。看起来你的onClick事件加载了歌曲?

你应该有:

<a href="javascript:void(0)" onclick="loadSong('849','http://bedupako.com/songs.php');return false;">play</a>

代替:

<a href="songs_related/create_play_list.php?single=0&amp;songid=849&amp;url=http://bedupako.com/songs.php" onclick="loadSong('849','http://bedupako.com/songs.php');return false;">play</a>

现在,您告诉javascript用onClick事件加载您的歌曲,并告诉浏览器使用HREF转到另一个URL。javascript:void(0)将阻止浏览器执行HREF。

实际问题在于我执行回调后返回的值为false!!!

以下是更正后的JS:

function callBackForLoadSong(data)
{
    //alert(data);
    if(data == "failed")
    {
        alert("Song requres you to login. Its easy to create an account! We will take you to the login page after you press ok");
        window.location.replace(REDIRECT);
    }
    else
    {
        //alert("s");
        $("#main_music_player_for_the_site").text("refreshing player...");
        $("#main_music_player_for_the_site").load("player_codes.php");
    }
    return false;
}

因此返回错误;必须在函数中也指定