Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对发送到php页面的ajax请求数据进行编码,然后解码_Javascript_Php_Jquery_Ajax_Post - Fatal编程技术网

Javascript 对发送到php页面的ajax请求数据进行编码,然后解码

Javascript 对发送到php页面的ajax请求数据进行编码,然后解码,javascript,php,jquery,ajax,post,Javascript,Php,Jquery,Ajax,Post,我有一个使用ajax到外部php页面的https请求,如下面的代码所示。请注意,有一些奇怪的非UTF-8字符必须进行编码,否则我会得到一个奇怪的返回 //ajax request to external site sometext = "I only wear Rtrtrr® shoes, and my name is Åron"; sometext = some_encoding(sometext); //a PSEUDO code line $.ajax({ type: "PO

我有一个使用ajax到外部php页面的https请求,如下面的代码所示。请注意,有一些奇怪的非UTF-8字符必须进行编码,否则我会得到一个奇怪的返回

//ajax request to external site
sometext = "I only wear Rtrtrr® shoes, and my name is Åron"; 

sometext = some_encoding(sometext); //a PSEUDO code line

$.ajax({
    type: "POST",
    url: "http://targetsite.com/process_text.php",
    data: sometext,
    cache: false,
    success: function(proc_text) {
        alert()
    }
 });    
在php页面上,我需要解码并使用一些解码(sometext)而不是一些编码(sometext)

有没有办法对这样的文本进行编码,使用some_编码function i javascript,它在php中具有模拟解码功能


例如,encodeURIComponent不会转换所有字符,而在某些情况下,我使用的Base64在PHP和Javascript中并不相同。是否存在相同的问题。

如果使用“我是否应该将文本转换为utf-8,然后在返回时对其进行解码?”则不会出现此问题。默认情况下,ajax使用utf-8。将页面字符集设置为utf-8和db,一切都将顺利进行,无需编码/解码文本是用户输入,我无法控制它。我的字符集是UTF,你是这个意思吗。但有时请求还是有点被打破了。