dave
dave

Reputation: 1009

Getting 'commentcontent' via ajax

I'm building up an ajax function that grabs the info needed to send into the database than print it out on the page. Only it grabs the streamid but not the commentcontent. I can see this in firebug under the post parameters. The strange thing is, I've used the same method for my main status updates and just changed the id's so they don't conflict.

Most would say there is no value in the commentcontent..but that would be the users inserted comment, and their is no value on my main status updates..So I'm rubbing my head thinking, where am I going wrong?

FORM

 <form id='mycommentform' method='POST'  class='form_statusinput'>
    <input type='hidden'  name='streamid' id='streamid' value='".$streamitem_data['streamitem_id']."'>
    <input class='text' name='commentcontent' id='commentcontent' placeholder='Say something' autocomplete='off'>
    <input type='submit' id='button' value='Feed'>
    </form>
    </div>

AJAX

 <script>
    $(document).ready(function(){
    $("form#mycommentform").submit(function(event) {
    event.preventDefault();
    var streamid = $("#streamid").val();
    var commentcontent = $("#commentcontent").val();

    $.ajax({
    type: "POST",
    url: "comment_add.php",
    cache: false,
    dataType: "json",
    data: {  streamid:  streamid, commentcontent: commentcontent}, 
    success: function(response){ 
     $("#commentcontent").val(""); 
    $("#commentaddid").html("<div class='stream_comment_holder' style='display:none;' id='comment_holder_"+response['streamitem_id']+"'><div id='comment_list_"+response['streamitem_id']+"'></div></div>");
    }
    });
    return false
    });
    });
    </script>

Upvotes: 0

Views: 33

Answers (1)

orhanhenrik
orhanhenrik

Reputation: 1415

You always need to quote your data, so changing it to: { 'streamid': streamid, 'commentcontent': commentcontent} should probably fix your issue

After some discussion, we found out
var commentcontent = $(this).children('#commentcontent ').val();
fixed the issue

Upvotes: 1

Related Questions