jQuery旧版本与新版本冲突

时间:2017-04-26 21:35:27

标签: jquery

我使用Bootstrap 3,因为我需要jQuery 1.9.1。

对于所有的ajax调用和jQuery选择器都是在最新版本的jQuery上设置的。

但另一方面,我使用的广告需要较旧版本的jQuery,如1.2和Bootstrap不支持它。

我的功能适用于所有新的jQuery并播放歌曲并更新一些div和属性。在同一个函数中,我必须调用支持旧版jQuery的添加代码。

但是冲突即将到来,如果我使用更新的版本所有Bootstrap和ajax工作正常,但ADD不起作用,如果我使用旧版本ADD工作正常,其他一切都没有。

显示以下代码。如果有人能帮助我,我需要一个解决方案或修复方案。

function loadVideo(ID,myFile, title, image, views, fav, buyurl) {

    //THIS IS MY ADD FUNCTION
    requestAdHandler();

    //ALL OTHER CODE
    setTimeout(function(){mediaElement.play();}, 9000);
    $(".player-container").css("display", "block");
    $("#myElement").css("display", "block");
    jwplayer("myElement").setup({
      file: myFile,
      width: '100%',
      height: 30,

      skin: {
       name: "mySkin",
       active: "#4FBFFB",
       inactive: "#ccc",
       background: "black"
    }
    });

    $('.song-title').html(title);
    $('#player-img').attr('src','/audio/images/'+image);
    $('#player-views').html(views);
    $('#player-fav').html(fav);
    $('#player-buy').attr('href', buyurl);
    $('#player-twitter').attr('href', 'http://twitter.com/home?status='+title+'+http://pavementchasers.com/songs/'+ID);
    $('#player-facebook').attr('href', 'http://www.facebook.com/share.php?u=http://pavementchasers.com/songs/'+ID+'&title='+title);

    jwplayer().load([{
      file: myFile
    }]);
    jwplayer().play();

    //AJAX View Update
    $.ajax({
    method: 'POST', // Type of response and matches what we said in the route
    url: '/viewupdate/'+ID, // This is the url we gave in the route
    data: {'id' : ID, '_token': '{{ csrf_token() }}'}, // a JSON object to send back
    success: function(response){ // What to do if we succeed
        console.log(response.views); 
        $('#view-'+ID).html(response.views);
    },
    error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
        console.log(JSON.stringify(jqXHR));
        console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
    }
    });


  };
</script>

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用较新的版本?旧版本的大部分功能都包含在较新版本中。

或者,您可以使用jQuery no conflict方法将您的某个版本上的jQuery命名空间映射到不同的命名空间。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.noConflict demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<div id="log">
  <h3>Before $.noConflict(true)</h3>
</div>
<script src="https://code.jquery.com/jquery-1.6.2.js"></script>

<script>
var $log = $( "#log" );

$log.append( "2nd loaded jQuery version ($): " + $.fn.jquery + "<br>" );

// Restore globally scoped jQuery variables to the first version loaded
// (the newer version)

jq162 = jQuery.noConflict( true );

$log.append( "<h3>After $.noConflict(true)</h3>" );
$log.append( "1st loaded jQuery version ($): " + $.fn.jquery + "<br>" );
$log.append( "2nd loaded jQuery version (jq162): " + jq162.fn.jquery + "<br>" );
</script>

</body>
</html>

https://api.jquery.com/jquery.noconflict/

相关问题