简体   繁体   English

成功调用JQUERY的函数

[英]Calling a function on JQUERY success

I have a custom function that I have defined and then I subsequently call when the the page loads. 我有一个已定义的自定义函数,然后在页面加载时调用。 I need the function to run when the page loads because it is populating a group selectlists: 我需要该功能在页面加载时运行,因为它正在填充组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>

I am trying to call my custom function PopulateSelectLists() when another AJAX call successfully completes so I can refresh my selectlists but it never seems to call my function: 我试图在另一个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>

Where am I going wrong here? 我在哪里错了?

In the problematic case, does the request actually return successfully? 在有问题的情况下,请求实际上是否成功返回? Inspect the response with Firebug or Fiddler or whatever dev toolbar you are using. 使用Firebug或Fiddler或您使用的任何开发工具栏检查响应。 It may be that there is a server error, a connection error, or any other reason that can drop the request, so it is not successful. 可能是服务器错误,连接错误或任何其他可能导致请求丢失的原因,因此请求未成功。

You can also look into using the complete handler: http://api.jquery.com/jquery.ajax/ . 您也可以使用完整的处理程序进行调查: http : //api.jquery.com/jquery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM