使用javascript发送特殊字符

使用javascript发送特殊字符,javascript,php,Javascript,Php,我使用javascript和$\u POST方法发送用户名。 它使用简单的用户名,但使用具有特殊字符(如“Al[!]e$e”)的用户名时出现问题,并且在我的数据库中找不到用户名 <div class="friend-add"> <form method="post" action="" class="form-inline"> <fieldset> <input name="username" id="username" placeholder="Us

我使用javascript和$\u POST方法发送用户名。 它使用简单的用户名,但使用具有特殊字符(如“Al[!]e$e”)的用户名时出现问题,并且在我的数据库中找不到用户名

<div class="friend-add">

<form method="post" action="" class="form-inline">
<fieldset>
<input name="username" id="username" placeholder="Username" autocomplete="off" type="text">
<button id="add_friend" name="add_friend" type="submit" class="btn">Add friend</button>
</fieldset>
</form>
<div id="loading_m" style="position:relative; width:16px; height:16px; float:left; margin-top:-30px;margin-left:330px;background-image:url(loading.gif); background-repeat:no-repeat; background-size:16px 16px; display:none;"></div>
</div>


<script language="javascript" type="text/javascript">
$("#add_friend").click(function(){
$("#add_friend").attr("disabled","disabled");
$("#loading_m").fadeOut('fast');
$("#loading_m").fadeIn('fast');
$("#alert_m").html("");
$.post("friend_request.php", { friend_username : $("#username").val() })
    .done(function(data) {
        //alert(data);
        if (data.toLowerCase().indexOf("notexist") >= 0){
            $("#loading_m").fadeOut('fast',function(){
                $("#alert_m").html("<b style='color:#FF0040;'>This user does not exist.</b>").fadeIn('fast').delay(5000).fadeOut('fast');
                $("#add_friend").removeAttr('disabled');
            });
        }

        ......

                .fail(function(){
        $("#loading_m").fadeOut('fast',function(){
                $("#alert_m").html("<b style='color:#F00;'>Something wrong with server please try again later.</b>").fadeIn('fast').delay(5000).fadeOut('fast');
                $("#add_friend").removeAttr('disabled');
            });
     });
     return false;


});

加朋友
$(“#添加朋友”)。单击(函数(){
$(“添加朋友”).attr(“禁用”、“禁用”);
$(“#加载m”).fadeOut('fast');
$(“#加载m”).fadeIn('fast');
$(“#alert_m”).html(“”);
$.post(“friend_request.php”,{friend_用户名:$(“#用户名”).val()})
.完成(功能(数据){
//警报(数据);
if(data.toLowerCase().indexOf(“notexist”)>=0){
$(“#加载μm”).fadeOut('fast',function(){
$(“#alert_m”).html(“此用户不存在”).fadeIn('fast')。delay(5000)。fadeOut('fast');
$(“#添加朋友”).removeAttr('disabled');
});
}
......
.fail(函数(){
$(“#加载μm”).fadeOut('fast',function(){
$(“#alert_m”).html(“服务器有问题,请稍后再试”).fadeIn('fast')。delay(5000)。fadeOut('fast');
$(“#添加朋友”).removeAttr('disabled');
});
});
返回false;
});

为什么要使用编码器组件:

编辑:在php中使用urldecode()将其转换回原始字符串

$username = urldecode($_POST['friend_username']);

Ref:

请提供更多信息,我是如何做到这一点的?
$username = urldecode($_POST['friend_username']);