I'm trying to get the "data-postid" attribute from this HTML/PHP code, which I am then trying to use to get the unique div clicked which will then display the appropriate lightbox on click (I'm using a WordPress site, hence the Wordpress code):
EDIT: Changed the code to show current versions, and a new file called "myfile.php"
HTML/PHP Code (index.html):
<div class="person-row">
<div id="post-<?php the_ID() ?> <?php post_class(); ?>" class="person" data-postid="<?php the_ID() ?>">
</div>
JQuery Code (script.js):
var $post = $(this);
var identifier = ($post.data("postid"));
$.ajax({
url: "myfile.php",
type: "POST",
data: { postNumber: (identifier) },
dataType: "text",
success: function(response) {
alert(response);
}
});
Then trying to get it back into the PHP to use
PHP Code (myfile.php)
<?php $post = $_POST['postNumber'] ?>
PHP Code (index.html)
<?php $PID = $_GET['postNumber'] ?>
Any help would be much appreciated. If there is anything else you need to know I'll be happy to supply it.
the_ID()PHP function contain?htmlspecialcharswhen outputting to HTML to prevent XSS.data: { postid: $post.attr("id") }as you've used "id" as an attribute in your html instead of "data-postid" (attribute name instead of attribute value).