|
JQuery post returns everything.
Hi all, I simply want to post what was entered in a textarea in a div I have just below it but when I fire the post ajax function it returns everything, and I mean the entire site. I don't understand why, can somebody help me please? This is the code I have:
[code]
jQuery(document).ready(function() {
$('#commentPad textarea').focus();
$('#commentPad textarea').keyup(function(e) {if(e.keyCode==13) saveComment();});
function saveComment() {
$.post(
'index.php/dashboard/saveComment'
,{comment:$('#commentPad textarea').val()}
,function(data) {$('#comments').html(data);}
);
}
});
[code]
HTML is this:
[code]
<div id='commentArea'>
<div id='commentPad'>We'd like to hear from you:<br /><span>(Enter to submit)</span><textarea></textarea></div>
<div id='commentListBox'>Comments:<br /><div id='comments'></div></div>
</div>
[code]
and my controller php function is this:
[code]
public function saveComment() {
if(!empty($_POST['comment'])) {
$comment=$_POST['comment'];
echo "<p>$comment</p>";
}
}
[code]
Last edited by christopherc; 03-14-2012 at 08:53 AM..
|