一次使用AJAX填充两个不同的组合框 [英] Populate two different combo boxes using AJAX at a time

查看:140
本文介绍了一次使用AJAX填充两个不同的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3组合框:部门,课程,活动。部门组合框,将从部门表中加载所有部门。我需要将课程加载到一个组合框中,并将活动加载到属于某个部门的另一个组合框中。表格模式如下所示。

I have 3 combo box: Department, Courses, Activities. The Department combo box which will load all departments from the department table. I need to load the courses in one combo box and activities in another combo box which belong to a department. The table schema is shown below.

    Department Table
    ----------------
    | Dept | Name  |
    ----------------
    | 1    | Dept1 |
    | 2    | Dept2 |
    ----------------

    Department Course Table
    ----------------------
    | Cid |Dept | Course |
    ----------------------
    | 1   | 1   | abc    |
    | 2   | 1   | xyz    |
    | 3   | 1   | pqr    |
    | 4   | 2   | bar    |
    | 5   | 2   | foo    |
    ----------------------

    Department Activities Table
    ---------------------------
    | Aid | Dept | Activities |
    ---------------------------
    | 1   | 1    | foo1       |
    | 2   | 1    | foo2       |
    | 3   | 1    | foo3       |
    | 4   | 2    | bar1       |
    | 5   | 2    | bar2       |
    ---------------------------

部门组合框将加载部门1和部门2.
当选择Dept1时,属于Dept1的课程应加载到Courses组合框(abc,xyx,pqr)属于Dept1的活动应在活动组合框(即foo1,foo2,foo3)中加载。

Department combo box will load Dept 1 and Dept 2. When Dept1 is select the Courses which belong to Dept1 should load in Courses combo box i.e (abc,xyx,pqr) and Activities which which belong to Dept1 should load in Activities combo box i.e (foo1,foo2,foo3).

如何在AJAX或jQuery中同时调用两个函数?

How to call two functions at the same time in AJAX or jQuery?

推荐答案

您可以这样做:

$('#department_combo').change(function(){
    $.ajax({
        url: "/someUrl/courses",
        success: function(data) {
            // Populate courses with data
        }
    });
    $.ajax({
        url: "/someUrl/activities",
        success: function(data) {
            // Populate activities with data
        }
    });
});

这篇关于一次使用AJAX填充两个不同的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆