我正在使用jquery .html()通過調用REST url動態地添加一些標記,但它不起作用。jquery .html()不工作
<div style="display: none;" id="tables">
<form:select id="table" name="table" path="table">
<form:option value="">Choose</form:option>
<div id="tables-select">
<!-- The available tables for update will be added here -->
</div>
</form:select>
<script type="text/javascript">
function getTables(type) {
$.getJSON('/web/tables/db/' + type,
{
ajax : 'true'
},function(data) {
html ='';
var len = data.length;
for (var i=0; i<len; i++) {
html += '<option value="'+data[i]+'" >'+data[i]+'</option>';
}
$('#tables-select').html(html);
});
}
</script>
</div>
我看到REST調用正在進行,但沒有任何事情發生。 調試並放置中斷點後,我看到java腳本直接從第10行跳轉到java腳本函數結束(第20行)。
任何想法這裏發生了什麼? 我在我的頁面中有大量的相同類型的函數,並且所有這些工作都期待這個。
編輯:
這是怎麼了調用該函數
<script type="text/javascript">
$(document).ready(function(){
$("#type").live('change', function(){
var type = $(this).val();
getSites(type);
getTabless(type);
});
});
</script>
請縮進您的代碼以使其更具可讀性。謝謝。 – 2012-02-14 14:20:36
請不要在你的代碼中包含行號,它會弄亂格式。 – 2012-02-14 14:21:13
在第15行放置一個斷點。如果您沒有擊中該點,那麼AJAX呼叫無法正常工作。 – arb 2012-02-14 14:21:51