簡體   English   中英

成功調用JQUERY的函數

[英]Calling a function on JQUERY success

我有一個已定義的自定義函數,然后在頁面加載時調用。 我需要該功能在頁面加載時運行,因為它正在填充組selectlists:

<!---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>

我試圖在另一個AJAX調用成功完成時調用我的自定義函數PopulateSelectLists(),以便可以刷新我的選擇列表,但它似乎從未調用過我的函數:

<!---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>

我在哪里錯了?

在有問題的情況下,請求實際上是否成功返回? 使用Firebug或Fiddler或您使用的任何開發工具欄檢查響應。 可能是服務器錯誤,連接錯誤或任何其他可能導致請求丟失的原因,因此請求未成功。

您也可以使用完整的處理程序進行調查: http : //api.jquery.com/jquery.ajax/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM