php - 在页面加载时选择选项加载时触发事件

标签 php jquery ajax

我想获取基于所选行业类型的业务类型列表。我正在使用以下代码 -

$('#industry_type').change(function () {
    var industry_id = $(this).val();
    getBusinessTypes(industry_id);
    return false;
});

function getBusinessTypes(industry_id) {
    $.ajax({
        url: baseURL + ('processes/org_process.php'),
        type: "POST",
        data: { 'action': 'all', 'industry_id': industry_id },
        success: function (data) {
            var business_type = $('#business_types');
            business_type.chosen('destroy');
            business_type.html(data);
            business_type.chosen({ width: "100%" });
        }
    });
}

这将返回业务类型列表。

这里的问题是只有在更改选择选项时才会触发该事件。如果页面加载时已选择选择选项,则不会触发该事件。

有人知道如何根据页面加载时选定的行业类型获取业务类型列表吗?

谢谢!

最佳答案

绑定(bind)事件处理程序后添加.trigger('change')

$('#industry_type').change(function () {
    var industry_id = $(this).val();
    getBusinessTypes(industry_id);
    return false;
}).trigger('change');

关于php - 在页面加载时选择选项加载时触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46940515/

相关文章:

php - 如何使用 AJAX 调用 PHP 脚本来执行 jQuery 自动完成?

javascript - 如何将 codpen JS 和 AJax 添加到我的一个 WordPress 页面

php - 如果没有找到行,MySQL make count 不返回任何内容

javascript - ASP.NET MVC 通过单击按钮创建新的 Guid

javascript - JS 日历添加月份切换器

javascript - 如何通过 jquery 中的点击事件切换 ids?

ajax - Ajax调用中的异常处理

php - 在 Laravel 中搜索数组

php - 打开,恐惧和蜂拥而至

php - 具有可变参数的 Laravel 5.2 命名路由用法