I'm doing an Ajax call to my server and need to send an array. I'm encoding the array using JSON. That results in this data sent to the server using a POST request:
selection=%5B%221%22%5D
On the server, I have this code:
echo urldecode($_REQUEST['selection']);
This results in:
[\"1\"]
Note that there are no backslashes in the request. I checked that with Firefox's dev tools.
Where were the backslashes added? Am I doing something wrong here? I can't decode the string like this.
This is the client-side code:
$.ajax({
type: "POST",
url: "<my-uri>/rule/add.php",
data: {
selection: JSON.stringify(["1"]) // in reality this is a variable array
}
}).done(function(data){
alert(data);
});