problem with .load() after several click
why after of several click on '#icon a', hang browser will and is run code js bad.
Everything is bad to when refresh page. i use of chrome, firefox and ...$('#icon a').click(function (event) {
event.preventDefault();
var id = '#' + this.id;
var title = $(id).attr('title');
$(".title").toggleClass("suject").html(title);
var url = $(id).attr('href');
$('.table_show, #num_count, #select_box, #input_search').fadeOut('slow', function () {
$('.results').load(url, function(){开发者_开发问答
$(this).hide().show();
$.getScript("http://localhost/Siran-mehdi/files/js/admin.js");
})
//.hide().show("slow")
});
});
From the jQuery documentation (http://api.jquery.com/jQuery.getScript/)
This is a shorthand Ajax function, which is equivalent to:
$.ajax({ url: url, dataType: "script", success: success });
This means an asynchronous ajax call is being made every time the link is clicked, and is probably causing problems when clicked again before the ajax call finishes. You could try disabling the link until the ajax request completes.
Clicking several times on the link you run several ajax-requests. That is why it is hang browser will and is run code js bad
Try to disable link after innitial click and enable when ajax-request is finished.
I hope it will help
UPDATE
Firs you need to add some class the link. Let it be clickme
; Than your code will be like this. I have no time to test it, so it is just idea. It should work.
$('#icon a.clickme').live('click', function (event) {
var clickedLink=$(this);
clickedLink.toggleClass('clickme'); //disabling link
event.preventDefault();
var id = '#' + this.id;
var title = $(id).attr('title');
$(".title").toggleClass("suject").html(title);
var url = $(id).attr('href');
$('.table_show, #num_count, #select_box, #input_search').fadeOut('slow', function () {
$('.results').load(url, function(){
//if load function failed
//you may enable link there
$(this).hide().show();
$.getScript("http://localhost/Siran-mehdi/files/js/admin.js", function(){
clickedLink.toggleClass('clickme'); //enabling link
});
})
//.hide().show("slow")
});
});
精彩评论