从Jquery Post中删除转义字符 [英] Remove escape character from Jquery Post
问题描述
我想将JQuery对象转换为Json String,然后将此字符串发布到PHP webPage,这是非常好的。但是当我在服务器(php页面)上收到它时,它已经装满了转义字符。
这是我的客户端代码:
var jsonRemision = JSON.stringify(remision,FALSE);
$ .post(updateremision.php,
{
rem:jsonRemision,
contentType:application / json; charset = utf-8,
dataType:json,
processData:false,
},
函数(数据,状态){
if(status ==success ){
alert(Good Message);
} else {
alert(Bad Message);
}
});
这里是服务器上的代码:
$ remision = json_decode($ _ POST ['rem']);
现在,当我看到$ _POST里面有什么['rem']里有一些转义字符\\ \\这些转义字符不允许我jsondecode ... json充满了转义字符如下所示:
{ \ id\:\ 12\,\ fecha\:\ 2014-06-25\,\ ciudad\:\Manizales\ \ camion\:\ NAQ376\,\ driver\:\ 16075519\,\ cant\:\ 0\ \ anticipos\:[{\ type\:\ 1\,\ com\:\ Comment\,\ costo\: \1234\}]}
如何删除转义字符?
我实际上刚刚有同样的问题。
我通过使用stripslashes();
修复它应该可以正常工作,除非你确实有斜杠数据。
var_export(json_decode(stripslashes('{\id\:\12\ \ fecha\:\ 2014-06-25\,\ ciudad\:\ Manizales\,\ camion\:\NAQ376\\ \\ \ driver\:\ 16075519\,\ cant\:\ 0\,\ anticipos\:[{\ type\\ \\:\1\,\com\:\Comment\,\costo\:\1234\}]}'),true) );
输出:
code> array(
'id'=>'12',
'fecha'=>'2014-06-25',
'ciudad'=& Manizales',
'camion'=>'NAQ376',
'driver'=>'16075519',
'cant'=>'0',
' expectos'=>
数组(
0 =>
数组(
'type'=>'1',
'com'=&评论',
'costo'=>'1234',
),
),
)
To my issue there are several similar questions but I haven't found a good one that would help me solve my problem. My problem is:
I want to convert a JQuery object into a Json String, and then post this string to a PHP webPage, This is running very good. But when I received it on the server(php page) it is full of escape characters.
Here is my code on the client:
var jsonRemision = JSON.stringify(remision,false);
$.post("updateremision.php",
{
rem:jsonRemision,
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
},
function(data,status){
if(status=="success"){
alert("Good Message");
}else{
alert("Bad Message");
}
});
and here is the code on the server:
$remision = json_decode($_POST['rem']);
Now, when I see whats inside of $_POST['rem'] is full of escape characters \" . These escape character are not allowing me to jsondecode... The json full of escape characters looks like this:
{\"id\":\"12\",\"fecha\":\"2014-06-25\",\"ciudad\":\"Manizales\",\"camion\":\"NAQ376\",\"driver\":\"16075519\",\"cant\":\"0\",\"anticipos\":[{\"type\":\"1\",\"com\":\"Comment\",\"costo\":\"1234\"}]}
How can I remove the escape characters ?? thanks in advance for any comment or help :)
I actually just recently had the same issue.
I fixed it by using stripslashes();
This should work ok unless you actually do have slashes in the data.
var_export(json_decode(stripslashes('{\"id\":\"12\",\"fecha\":\"2014-06-25\",\"ciudad\":\"Manizales\",\"camion\":\"NAQ376\",\"driver\":\"16075519\",\"cant\":\"0\",\"anticipos\":[{\"type\":\"1\",\"com\":\"Comment\",\"costo\":\"1234\"}]}'), true));
outputs:
array (
'id' => '12',
'fecha' => '2014-06-25',
'ciudad' => 'Manizales',
'camion' => 'NAQ376',
'driver' => '16075519',
'cant' => '0',
'anticipos' =>
array (
0 =>
array (
'type' => '1',
'com' => 'Comment',
'costo' => '1234',
),
),
)
这篇关于从Jquery Post中删除转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!