2017-04-26 163 views
0

我使用Bootstrap 3,因爲我需要jQuery 1.9.1。jQuery舊版本衝突與新版本

對於所有的ajax調用和jQuery選擇器都設置了最新版本的jQuery。

但另一方面,我使用的廣告需要1.2版本的jQuery的老版本,而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

您是否嘗試過使用較新的版本?較新版本中的大部分功能都包含在較新版本中。

或者,您可以使用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/

+0

我要調用一個函數和SDK我的ADD,當我使用最新的jQuery文件SDK提供了錯誤。在哪裏使用jQuery.noConflict(true);這是我的函數requestAdHandler();我擔心這不會幫助我,或者你可以根據我的代碼解釋我反正謝謝幫助我! – zeeshan