Reputation: 22040
Is there an alternative to .load() in jQuery?
Upvotes: 6
Views: 23592
Reputation: 1021
$('#test_image').ready(function() {
alert("fully loaded !!!");
});
Try this it will work
Upvotes: 1
Reputation: 11
If you need something to happen on page load, do it relative to the document.
Example:
$(document).ready(function(){
var var_name = $(this).find(".div_class").children(".child_div").height();
$(this).find(".div_class").css("min-height", var_name);
});
Here I use the find()
function with the document as relative parent, instead of using load()
with the div as the relative parent.
Upvotes: 0
Reputation: 4667
for jquery lib > 1.7
$('#test_image').on("load",function() {
alert("fully loaded !!!");
});
Upvotes: 1
Reputation: 1021
Use $.ajax instead of .load function. But make sure you specify the dataType as html for the ajax function. .load is just a shorten version of $.ajax function where the dataType is html.
$.ajax({
url: 'url to load',
dataType: 'html',
success: function(html) {
... rest of your code that should be added into the load function.
}
});
Upvotes: 3
Reputation: 3217
As has been mentioned you can use $.ajax() directly.
Here is an example of this.
function update_user_ajx(user_id){
var data = {
username: $('#UsernamePost_' + user_id).val(),
password: $('#PasswordPost_' + user_id).val(),
email: $('#EmailPost_' + user_id).val(),
accesslevel: $('#AccessLevelPost_' + user_id).val()
};
$.ajax({
url: "/managesettings/updateuser/" + user_id,
type: "POST",
data: data,
cache: false,
success: function (html) {
/* Replace Content */
$('#UpdateUsers').html(html);
/* Try Fade In */
$('#UpdateUsers').fadeIn('slow');
}
});
}
Upvotes: 0
Reputation: 630429
Yes, you can use $.ajax()
directly if you need additional control over what .load()
offers.
There are also other $.ajax()
shorthand methods available.
Upvotes: 11