jquery - Sending data via AJAX not working - why? -


i creating jquery function send data via ajax , open div result:

<div class="comments_div" id="comments_div" data-id='<?php echo $post_id; ?>' ">    more comments--->   <div class="comments_more_<?php echo $post_id; ?>" id="comments_more">  
$(function() {   $(".comments_div").click(function() {     var post_id = $(this).attr('data-id');            $.ajax({       url: "jscripts/comment_query.php",       type: "post",       data: post_id,       success: function(datos) {         $('.comments_more_' + post_id).html(datos);         $('.comments_more_' + post_id).show('slow');         //alert(post_id);       }     });   }); }) 

alert(post_id) shows correct post_id. reason does't send data.

comment_query.php:

<?php     echo 'post_id: ';     echo $_post['post_id']; ?> 

the div comment_more opens , show text "post_id: " (but not variable).

the issue because you're not providing key post_id value when send in request.

you can either using form-urlencoded format:

data: 'post_id=' + post_id, 

or, more preferably, providing object jquery serialise , encode you:

data: { post_id: post_id }, 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -