我是新來的Javascript和Ajax,並試圖找出爲什麼我的代碼不起作用。Javascript,Ajax和Alert不工作
<script type="text/javascript">
$(document).ready(function() {
$('.cadlib').bind('click', function() {
$.get("/models/"+this.id+"/viewmodelinfo/", function(data) {
alert ("yo"); // This line bellow doesn't execute
if (data.fact_type=="T") {
guess_result="This fact is true! " + data.fact_note;
} else {
alert ("yo");
guess_result="This fact is false! " + data.fact_note;
}
$('#result').replaceWith("guess_result");
});
});
});
</script>
這裏是我的HTML
<a href = "#mySymbolModal" class = "cadlib" id = "{{symbol.id}}" data-toggle="modal" style = "text-align:center; color: #FF761A;" href="/models/{{symbol.id}}/view_model/"><span id = "modelname"> {{symbol.modelname.upper}}</span> - <span id = "format">{{ symbol.format }}</span><span id = "adder" style="visibility:hidden;">{{symbol.adder}}</span><span id = "adderid" style="visibility:hidden;"> {{symbol.adder.id}}</span><span id = "symbolobject" style="visibility:hidden;">{{symbol}}</span></a>
我覺得有一些錯誤的註釋行。我的警報沒有實例化。
有什麼我失蹤,會導致警報不工作?
[從jQuery 1.7開始,'.on()'方法是將事件處理程序附加到文檔的首選方法。](http://api.jquery.com/bind/#bind - 事件) – fardjad 2013-04-05 05:41:15
控制檯中是否有任何錯誤 – 2013-04-05 06:01:31
是第一個顯示的警報 – 2013-04-05 06:01:59