当我输入“你好??” 在文本区域 (id = add_new_comment) 它插入hellojQuery1704879437133033947_1333718592556?? 在数据库中。代码有什么问题?提前致谢
$('#add_new_comment').live('keyup',function (event) {
/*shft+enter for new line*/
if (event.keyCode == 13 && event.shiftKey) {
$(this).val($(this).val()+"\n");
return false;
}else if(event.keyCode == 13){
/*code to be inserted in db*/
}
});
数据库代码(即 codeigniter 中的模型)
function add_new_comment($comment, $store_id, $comment_source,$user_id) {
$data = array(
'comment' => $comment // comment to be inserted. This contains the text of textarea.
'source_id' => $store_id,
'comment_source' => $comment_source,
'from_user_id' => $user_id
);
$result = $this->db->insert(COMMENTS, $data);
return $this->db->insert_id();
}
js脚本(实际代码):
$('#add_new_comment').live('keyup',function (event) {
if (event.keyCode == 13 && event.shiftKey) {
$(this).val($(this).val()+"\n");
return false;
}else if(event.keyCode == 13){
var store_id = "";
store_id = $('.c_store_comment').attr('id');
var new_comment = $.trim($(this).val());
$.ajax({
type:'post',
url:path to controller,
data:'comment='+new_comment+'&store_id='+store_id,
dataType:'json',
success:function(vals){
$.each(vals,function(i,values){
switch (i) {
case 'error':
alert('Sorry Something went Wrong');
break;
case 'success':
var comment_div = '<div class="col1_comment2_row"><div class="col1_comment2_row_tilte">'+$('.user_name').html()+'</div>';
comment_div += '<div class="col1_comment2_row_img"><a href="#nodo"><img class="delete_comment" id="'+values[1]+'" src="/images/delete_comment.png"></a> </div>';
comment_div += '<div class="col1_comment2_row_cooment">'+values[0]+' </div></div>';
$('.c_store_comment .scroll_container').append(comment_div);
$('#add_new_comment').val('');
break;
}
});
}
});
}
});