Im trying to make something like this http://demos.99points.info/facebook_wallpost_system/ which is a comment system. I have the ajax code below except i don’t know how to uniqely select textareas. The challenge is that the number of posts is variable so all of the posts need to be uniquely identified so that when the data is put …
via HTML Language Development » Search Results » ajax:
Jquery Ajax selectors
Im trying to make something like this http://demos.99points.info/facebook_wallpost_system/ which is a comment system. I have the ajax code below except i don’t know how to uniqely select textareas. The challenge is that the number of posts is variable so all of the posts need to be uniquely identified so that when the data is put into the database i know which post it relates to.
JQUERY:
$('.commentContainer').load('../writecomment.php');
//commentContainer is a class so it applies to all of the textareas, but i need this selector to be unique
$('.submitCommentBox').click(function()
//these are the selectors that i can't get to work right
var comment = $('').val();
var postid = $('').val();
$.post('../comment.php',
comment: comment,
postid: postid,
,
function(response)
$('#commentContainer').load('../writecomment.php');
$('.commentBox').val('');
}
return false;
}):
});
HTML/PHP
echo”
$post[$f]
“;
basically the HTML/PHP generates for each post on the page as to create a textarea and subimt button for each post. therefore the user can comment on each post.
……………………………………….
Using the markup in the link you provided, I would do something like:
var container = $(this).closest(‘.friends_area’);
var comment = $(container).find(‘.commentbox’).val();
var questionid = $(container).find(‘#hidden’).val();
var answerid = $(container).find(”).val();
A more correct solution would be something like:
HTML
…
JS
$(‘#posting’).on(‘submit’, ‘form’, function(e)
e.preventDefault();
var form = $(this).closest(‘form’);
$.post($(form).attr(‘action’), $(form).serialize(), function()
$(‘#commentContainer’).load(‘../writecomment.php’);
$(‘.commentBox’).val(”);
);
});
For more info: Jquery Ajax selectors
HTML Language Development » Search Results » ajax
Jquery Ajax selectors
L'articolo Jquery Ajax selectors sembra essere il primo su Ajax Time.