php - AJAX Show/hide content -
before complains ive tried google there isnt straight forward answer or tutorial of sort..
basically ive got articles paragraph seen *read more" link using javascript shows more content, although slow down website rest of article there hidden.
so question how set ajax/php bring in content instead? know how set database on mysql , right in guessing need type out article in mysql when storing in there? sorry if im saying confusing im confused myself... if explain absolute beginner great google isn't friend after hours of searching.
think ive been misunderstood. above screenshot ive achieved im wanting instead of hiding content displaying on-click have being called in using ajax, database , php
- add "previewcutoffindex" or similar articles table.
- on page load, display article html / content cutoff index.
- for "read more" button, put article identifier attribute
- add click handler makes ajax call, load rest of article
markup ("data-article-id" comes php on page load):
<div> <?php echo $mysqlresult["articlecontent"]; ?> </div> <a id="morebutton" data-article-id="<?php echo $articleid; ?>" href='#'>read more</div> <div id="morecontent"></div>
javascript (assume you're going use jquery):
$("#morebutton").on("click", function(e) { e.preventdefault(); var articleid = $(this).attr("data-article-id"); // load article "morecontent" div $("#morecontent").load("content.php?articleid=" + articleid); });
then php content.php
should return text (or more markup) remainder of article, based on $_get("articleid")
.
Comments
Post a Comment