首页 > 解决方案 > 在 Jquery.post 调用的 .done 中调用函数

问题描述

我对此感到困惑。

我试图在完成的 AJAX 中调用另一个定义的函数,但我得到函数找不到错误。

我还尝试将其声明为变量并使用它仍然遇到相同的问题,找不到该函数。

var self = this
...
$.post.done(function(respose) {
    self.init_customer_dropdown();
})

如果我在 AJAX 请求之外调用函数工作正常

这是完整的代码块

$('.save-client-modal').on('click', function(e) {

e.preventDefault();
//Save Cutomer to Database

var url = admin_url + "clients/create_client_ajax";

var data = {};
...

$.post(url, data).done(function (response){
    response = JSON.parse(response);

    if(response.success == true || response.success == "true")
    {
         init_customer_dropdown(); <-- will not run this function
    }
    else
    {
        alert_float('warning', response.message);
    }
});

});

function init_customer_dropdown()
{
    alert("Customer Dropdown");
}

在此先感谢迈克

标签: javascriptjqueryajax

解决方案


推荐阅读