首页 > jq ajax提交Code="encodeURIComponent('你好')" php获取$_POST["Code"]

jq ajax提交Code="encodeURIComponent('你好')" php获取$_POST["Code"]

jq ajax提交Code="encodeURIComponent('你好')" php获取$_POST["Code"]为什么是你好 而不是编码

我想要获得编码应该怎么办

想实现 var str = '<div style="color:red;">你好</div>';

通过jq ajax提交 str 在php后台获取到str这个字符串 求大神


js:
var str = '<div style="color:red;">你好</div>';
$.ajax({
    url:'./yoururl',
    data:{'str':str},
    type:'post',
    dataType:'json',
    beforeSend:function(){
        //
    },
    success:function(res){
        if(res.status == 0){
            //成功
        }else{
            alert(res.message);
        }
    }
})

php:

$str = isset($_POST['str'])?trim($_POST['str'])?:'';
if($str){
    echo json_encode(array('status'=>0,'message'=>'ok'));
}else{
    echo json_encode(array('status'=>-1,'message'=>'接收失败'));
}
die;
【热门文章】
【热门文章】