如何在执行另一个功能之前等待某个功能完成?

时间:2014-06-24 11:12:40

标签: javascript

我想首先说我找到了其他类似的问题,但我不明白如何使用我的代码执行,因为它不是我自己创建的函数。

我有以下代码:

$("#dataset").load('/hemaexplorerbeta/php/getDataset.php');

这会加载一些数据并输入下拉列表。

之后我正在调用以下内容,看看当我需要列表时它是否已加载:

document.getElementById('dataset').value

这些都是我负载的文件,我需要它们。如何在下载数据后确保从“#dataset”获取值?是的,数据是从MySQL数据库中提取的。

2 个答案:

答案 0 :(得分:1)

您可以将函数作为第二个参数传递。 例如:

$("#dataset").load('/hemaexplorerbeta/php/getDataset.php', function() {
  var x = document.getElementById('dataset').value;
});

答案 1 :(得分:0)

使用.load:

的回调函数
$("#dataset").load('/hemaexplorerbeta/php/getDataset.php', function() {
    // This gets executed when the content is loaded
    $(this).show();
});