2017-08-23 58 views
-1

在我的模板,我包括jqueryjquery.cookie.js,但得到下面的錯誤:我jquery.cookie.js報告錯誤

enter image description here

下面是我的html代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>cookie-login1</title> 
</head> 
<body> 

    <form action="/cookie/login1/" method="post"> 
     <input type="text" name="username"> 
     <input type="text" name="pwd"> 
     <input type="submit" value="add"> 
     <input id="btn" type="button" value="button-add"> 
    </form> 


</body> 


<script src="/static/js/jquery.cookie.js"></script> 
<script src="/static/js/jquery-2.1.4.min.js"></script> 

<script> 

    $(function(){ 
     $("#btn").click(function(){ 
      $.ajax({ 
       url:'/cookie/login1/', 
       type:"POST", 
       data:{'username':'root', 'pwd':'123'}, 
       success:function(response){ 

       } 
      }) 
     }) 
    }) 

</script> 

</html> 

我的jQuery版本是2.1.4,我的jquery.cookie.js版本是1.4.0

回答

1

你必須導入jQuery befor jquery.cookie.js
jquery.cookie.js需要jQuery,但你編譯器目前還不知道,因爲你在jQuery之前加載它。

<script src="/static/js/jquery-2.1.4.min.js"></script> 
<script src="/static/js/jquery.cookie.js"></script> 
+0

爲什麼?這是如何解決這個問題的?請解釋 –

1

HTML文檔解析順序是從上到下,你應該導入jquery第一:

<script src="/static/js/jquery-2.1.4.min.js"></script> 
<script src="/static/js/jquery.cookie.js"></script>