开发者

Executing code after a process is done - jQuery

开发者 https://www.devze.com 2023-03-29 03:04 出处:网络
I want to run: $(\".left\").load(\"created.php\"); after: $(\"#placeholder\").load(\"creat开发者_JAVA百科e.php\")

I want to run:

$(".left").load("created.php");

after:

$("#placeholder").load("creat开发者_JAVA百科e.php")

I tried the following, but it didn't work:

$("#create").live("click", function() {
 if($("#placeholder").load("create.php")) {
  $(".left").load("created.php");
 }
})


The jQuery load() function runs asychronously. You need to use a callback function to run code after the first load completes.

The following code should suffice:

 $("#create").live("click", function() {
   $("#placeholder").load("create.php", function() {
     $(".left").load("created.php");
   });
 });

Enjoy!


call the created.php in the call back of first load

$("#placeholder").load("create.php",null,function(){

$(".left").load("created.php");

});

jquery load


Execute it in the success handler of the previous load

$("#placeholder").load("create.php", function(){
   $(".left").load("created.php");
});


if($("#placeholder").load("create.php")) 

this line means load create.php then return a jqxhr object which is not what you mean. use callback of load method: $("#placeholder").load("create.php", function(data){...}) Or use $.when and .then instead

0

精彩评论

暂无评论...
验证码 换一张
取 消