當我輸入'hello ??'在文本區域(id = add_new_comment)中插入hellojQuery1704879437133033947_1333718592556 ??在數據庫中。代碼有什麼問題?由於提前與shft +相關的錯誤輸入並使用jquery輸入
$('#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*/
}
});
數據庫的代碼(即模型笨)
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;
}
});
}
});
}
});
有趣的乍得! 你是否也需要他的電子郵件密碼? :) – skafandri 2012-04-06 13:48:36
是因爲字符串中包含「??」在Ajax的數據屬性?即。 data:'comment ='+ new_comment +'&store_id ='+ store_id – 2012-04-06 13:56:10
將逃離'?'在這種情況下的字符串幫助? – 2012-04-06 13:57:25