我有一個自定義函數,我已經定義了,然後隨後在頁面加載時調用。我需要的功能,因爲它是填充一組selectlists運行該頁面加載時:在JQUERY成功上調用函數
<!---Populate Custom Service Description select lists --->
<script type="text/javascript">
function PopulateSelectLists(){
// Important: Must append the parameter "&returnformat=json"
$.ajax({
url: 'cfcs/get_descriptions.cfc?method=getDescriptions&returnformat=json'
, dataType: 'json'
, success: function(response){
$.each(response.DATA, function(I, row){
// get value in first column ie "description"
var description = row[0];
// append new option to list
$("#descriptionDD1").append($('<option/>', {
value: description,
text : description
}));
$("#descriptionDD2").append($('<option/>', {
value: description,
text : description
}));
$("#descriptionDD3").append($('<option/>', {
value: description,
text : description
}));
$("#descriptionDD4").append($('<option/>', {
value: description,
text : description
}));
});
},
error: function(msg){
console.log(msg);
}
})
}
$(document).ready(PopulateSelectLists);
</script>
我想打電話給我的自定義功能PopulateSelectLists()當另一個AJAX調用成功完成,所以我可以刷新我selectlists但似乎永遠不會打電話給我的功能:
<!---Script to add new description to DB --->
<script>
$(function(){
//Add a new note to a link
$("#addDescriptionForm").submit(function(){
// prevent native form submission here
$.ajax({
type: "POST",
data: $('#addDescriptionForm').serialize(),
url: "actionpages/add_descriptions_modal.cfm",
success: function() {
PopulateSelectLists(); //Call Function to refresh selectlist
$("#addDescriptionResponse").append("Successfully added description.");
}
});
return false;
});
});
</script>
我在哪裏錯了?
控制檯中是否存在錯誤?如果您將alert或console.log添加爲第一個成功行,您甚至可以獲得成功嗎?你調試了js嗎? – 2014-09-02 13:58:19
__it似乎永遠不會調用我的功能_ - 請看看控制檯,並添加一些調試console.log,即爲了驗證這 – 2014-09-02 13:59:36
我刷新了我的瀏覽器,我可以看到它現在工作。這可能是我的錯誤,因爲我認爲瀏覽器緩存正在搞砸了。 – 2014-09-02 14:54:51