2012-03-19 17 views
-2

工作我想打印網頁的HTML數據result使用jQuery的不是在Django

$("#regerror").html(result); 

不工作。但這樣做使用純javascript工作

document.getElementById("regerror").innerHTML = result; 

我使用Django。這就是我將庫包含在基本模板中的方式。

<script type="text/javascript" src="{{ MEDIA_URL }}jquery/js/jquery-ui-1.8.18.custom.min.js"></script> 
<script type="text/javascript" src="{{ MEDIA_URL }}base.js"></script> 
+4

做你的jQuery加載到頁面? – Shyju 2012-03-19 16:40:53

+2

jQuery庫是否包含在你的'head'標籤中? – Curt 2012-03-19 16:41:08

+4

你在頁面上有jquery嗎?似乎你不知道。在JavaScript控制檯中是否有任何錯誤? – 2012-03-19 16:41:17

回答

1

您很可能已經忘記了或錯誤地鏈接了JQuery庫,或者在加載庫之前調用它。

Here's a standalone告訴你它確實有效。

這是當前版本

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> 

這裏有一個簡單的例子

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> 
<script> 
$(document).ready(function(){ 
    $.ajax({ 
     url: "whatever.html", 
     success: function(result){ 
      $("#results").html(result); 
     } 
    }); 
}); 
</script> 

<div id="results"></div> 

RTFM...