Answer the question
In order to leave comments, you need to log in
Where do escape slashes come from when sending JSON to PHP?
Came across one feature in PHP.
Let's say we want to send some data in json format to the server using the GET method. For example, we have data:
var data = {
"value1" : "key1",
"value2" : "key2"
}
function doXHR (data) {
var xhr = getXMLHttpRequest(),
json = encodeURIComponent(JSON.stringify(data));
xhr.open('GET', 'http://domain.com/?json=' + json, true);
xhr.send();
xhr.onreadystatechange = function (e) {
console.log(e);
};
}
print_r($_GET['json']); // => {\"value1\":\"key\",\"value2\":\"key2\"}
print_r(json_decode($_GET['json'])); // => NULL
print_r(json_last_error()); // => 4
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question