Created
May 22, 2013 00:00
-
-
Save hbsnow/5624277 to your computer and use it in GitHub Desktop.
WordPressでつづきを読むの内容をajaxで取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(".more-link").click(function() { | |
| var $this = $(this); | |
| var $more = $this.parents(".entry-more"); | |
| var $content = $more.parents(".entry-content"); | |
| var file = $this.attr("href").replace("/#more", "/"); | |
| $more.remove(); | |
| $content.after("<div class='entry-content-more'><p class='more-loading'><span>now loading...</span></p></div>"); | |
| var $more_content = $content.next(); | |
| var request = $.ajax({ | |
| url : file, | |
| type : "POST", | |
| dataType : "html", | |
| timeout : 5000 | |
| }); | |
| request.done(function( data ) { | |
| var more_content = $( data ).find( "#more" ).html(); | |
| $more_content.html( "<div class='entry-content-more-single'>" + more_content + "<div class='entry-more-reply'><p><a href='" + file + "#respond'>Reply</p></div>" ); | |
| $more_content.find(".entry-content-more-single").animate( { opacity: 1 } ); | |
| }); | |
| request.fail(function( jqXHR, textStatus ) { | |
| $more_content.html("<div class='entry-content-more-single'><div class='alert-error'><p>Request failed: <strong>" + textStatus + "</strong></p><p>Sorry, please reload this page.</p></div>"); | |
| $more_content.find(".entry-content-more-single").animate( { opacity: 1 } ); | |
| }); | |
| return false; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment