繁体   English   中英

正则表达式转义双问号

[英]regex escape double question mark

我有一个社交网站,一切正常,我唯一的问题是,当我在评论或评论字段中输入双问号时,它显示出奇怪的文字。

==========

如果我输入“你好?” 它像“ hellojQuery110205576835835575724747_1411410901236”这样打印出来,我想知道如何转义特殊字符,在我的情况下是双问号。 没有正则表达式,还有没有更好的方法可以做到这一点。 提前致谢。 这是我的代码。

$(document).undelegate('.comment', 'keypress').delegate('.comment', 'keypress', function(e) {

                if ($.trim($(this).val()) !== '') {
                    if (e.which === 10 || e.which === 13) {
                        var comment = $(this).val();
                        var id = $(this).closest('.review_list').attr('id');
                        $.ajax({
                            type: 'POST',
                            url: '../controller/pageController.php',
                            data: 'review_id=' + id + '&comment=' + comment + '&luser_id=' + luser_id,
                            dataType:'json',
                            cache: false,
                            success: function(id) {
                                if($.trim(id)=='NO'){
                                 window.location='profile.php'; 
                                                     }
                                id = $.trim(id.id);
                                var c = "<li id='" + id + "'><div id='c_thumb'>"+(thumb != null ? '<img src="profile_images/' + thumb + '"/>' : '')+"</div><div id='commenter'><a href='userprofile.php?id="+luser_id+"'>" + name + "</a></div><div id='time'> 0 second ago</div><p>" + comment + "</p><a id='c_remove' href=''>remove</a></li>";

                                $('#comment_box li:last-child').before(c);
                                document.getElementById("post_comment").reset();
                            }//end of success
                        });

                    }
                }
            });

您需要正确编码URL参数。 一种方法是在每个参数上调用encodeURIComponent() ,但是由于您使用的是jQuery,因此我建议通过提供对象作为data:选项让它为您进行编码:

data: { review_id: id,
        comment: comment,
        luser_id: luser_id
      },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM