javascript - Append Dupplicates First Time -
I am facing two issues if someone can help me who would be great.
- Addend Duplicate. Blog Post For the first time when I try to click Load more buttons, but it works fine with the second click.
- Duplicate the same post again by clicking on a quick click or again
// AJAX load more Blog Post Function AJAXLoadMorePosts ($ {'(more .posts'). Click (function (e) {e.preventDefault (); // variable vari element = $ (this); var target = element.attr ('href' ); Var post_wrapper = $ ('.blog-post-wrapper'); / / AJAX $ .Jack up AJAX ({type: 'GET', url: target, success: function (data, textstats, xmlHttriwist) {// store New data var new_post_items = $ (data) .fi ('.blog-posts'); var next_page_url = $ (data) .find ('.nav-ago a'). Attr ('href'); // update load more button href (Next_page_url) {element.attr ('href', next_page_url);} and {element.slideUp ();} Post_wrapper.append (new_post_items);}, complete: function () {element.html (loadingTextOrg);}, error : Work (MLHttpRequest, textStatus, errorThrown) {warning (errorThrown);}})}};
In writing, AJAXLoadMorePosts ()
code> $ ('. Load-and-post ') With two results, click handler:
- No click handler is attached
called AJAXLoadMorePosts ()
for the first time - Call
AJAXLoadMorePosts ()
will later add more and more click operators, which are completely undesirable.
To attach a solution
You also need to make sure that the click handler performs a test as if it will only work Ajax if an AJAX request is already available Not in progress.
Something like this should be done.
// AJAX Load more blog posts $ (click 'Load-more- ($ Element.text () == loadingTextOrg) (Click, function (e) { E.preventDefault (); var $ element = $ (this); if ($ element.text () == loadingTextOrg) {var $ element = $ (this) .text (somethngElse); $ .get ($ element.attr ('Href'). Then (function (data, text position, xmlHttpRequest) {var next_page_url = $ (data) .find ('.rr'); if (next_page_url) {$ element.attr ('href ', Next_page_url);} and {$ element.slideUp ();} $ (' blog-post-wrapper '). Attachments ($ (data) .find (' .blog-post-wrapper.blog-post ') );}, Function (MLHttpRequest, textStatus, errorThrown) {Chet Subjected (errorThrown);}) always (function () {$ element.text (loadingTextOrg);});}});
Comments
Post a Comment