Reputation: 667
I am trying to pass some parameters to a php file and then load it on my page. After I do that I need to run a function. My problem is that jQuery runs the function before it loads the php file. I can get it working by adding a delay to my function using
setTimeout(function() {
addSet(id);
}, 500);
Instead I want it to run when my load function is done running. I have tried using $('#exer'+id).ready(function() { with no luck.
This is my code
function addExercise(id, name, type, factor, desc) {
$("<div id='exer"+id+"' class='exer'>lala</div>").insertAfter("#beforeExercises");
var php_file = "modules/ExerciseSearchTest2/addExercise.php?id="+ id + "&name=" + name + "&type=" + type + "&factor=" + factor + "&desc=" + desc;
$("#exer"+id).load(encodeURI(php_file));
addSet(id);
}
Upvotes: 0
Views: 55
Reputation: 50787
.load()
accepts a callback function to be fired only after the load has been completed.
$("#exer"+id).load(encodeURI(php_file), function(){
//this is the callback function, run your code here.
addSet(id);
});
Upvotes: 3