Reputation: 181
so im trying to get jquery to send an ajax call to update the comments database. i cant seem to find whats wrong with the code. been on the internets all day trying to find out.
<div class="comment">
<textarea name="comment" onkeydown="test(event)"></textarea>
</textarea>
</div>
function test(event) {
if (event.keyCode==13) {
var comment = $('textarea[name=comment]');
$.ajax({
type: "GET",
url: "commentupdate.php",
data: "comment=" + comment,
});
$('.comment').hide();
$('#container').isotope('reLayout');
}
}
commentupdate.php
include('MasterHub_DBCon.php');
$COOKIEINFO = $_COOKIE['masterhub_user']; $USERCOOKIEINFO = explode('+', $COOKIEINFO);
$comment = $_REQUEST['comment'];
$sql = "INSERT INTO `dmech_main`.`COMMENTS` (`ID`, `USERNAME`, `COMMENT`, `COMMENTID`) VALUES (NULL, \'' . $COOKIEINFO['0'] . '\', \'' . $comment . '\', \'' . $_SESSION['COMMENTID'] . '\');";
mysql_query($sql);
Upvotes: 0
Views: 218
Reputation: 7718
You missed the val()
I guess. Try -
var comment = $('textarea[name=comment]').val();
Instead of -
var comment = $('textarea[name=comment]');
Upvotes: 1
Reputation: 7856
Either you need to encode the data yourself and pass a string, or pass object:
<script type="text/javascript>
function test(event) {
if (event.keyCode==13) {
var comment = $('textarea[name=comment]');
$.ajax({
type: "GET",
url: "commentupdate.php",
data: "comment=" + encodeURIComponent(comment)
});
$('.comment').hide();
$('#container').isotope('reLayout');
}
}
</script>
<script type="text/javascript>
function test(event) {
if (event.keyCode==13) {
var comment = $('textarea[name=comment]');
$.ajax({
type: "GET",
url: "commentupdate.php",
data: { comment: comment }
});
$('.comment').hide();
$('#container').isotope('reLayout');
}
}
</script>
Quote from http://api.jquery.com/jQuery.ajax/ :
data
Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).
Upvotes: 0
Reputation: 998
I would try putting the javascript inside of a
<script>
tag to begin with.
Upvotes: 0