0

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);
}

1 Answer 1

3

.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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.