Home >Backend Development >PHP Tutorial >javascript - jq ajax提交Code="encodeURIComponent('你好')" php获取$_POST["Code"]

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

WBOY
WBOYOriginal
2016-06-06 20:07:19978browse

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

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

想实现 var str = '

你好
';

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

回复内容:

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

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

想实现 var str = '

你好
';

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

<code>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;</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn