How to call a function after an ajax page is completely loaded?
Using jQuery, I loaded an enrollment_forms.php
page into a div called container_level2
. When the enrollment_forms.php
page is loaded in this container_level2
I want to call another function.
How can I do this using one function with parameters?
Here is a function I've made:
function view_update_load_form(list_index, student_id){
$.ajax({
url: "enrollment_forms.php",
success: function(result){
$('#container_level2').html(result);
},
complete: function(){
load_form(list_index, student_id);
}
});
}
In the above code I call function with two parameters:
view_update_load_form(list_index, student_id开发者_如何学C)
This function loads a page:
enrollment_forms.php.
when enrollment.forms.php
is loaded, I want to call second function:
load_form(list_index, student_id)
with same paramters.
How can I? This doesn't work. It often calls 2nd function even if page is not completely loaded.
You could put the load_form
call inside your success
function:
success: function(result){
$('#container_level2').html(result);
load_form(list_index, student_id);
},
That way it won't be called before inserting the html.
Use
ajaxComplete();
Please refer the following link for more information JQuery ajaxComplete
精彩评论