I am serializing a string to be able to send to a php script, but the function leaves the string with / instead of /.
I would like to remove the \
from the string.
Can you help me ?
The function I use :
$scope.serialize = function(obj, prefix) {
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
I am using this function to send to a file :
$scope.send = function(){
// sendToServer.f($scope.serialize($scope.line))
sendToServer.f($scope.line)
.success(function(){
console.log('SUCESS ! sent to angualar-seed/db.jsonp, using appendToDb.php !')
})
.error(function(){
console.log('ERROR !')
});
}
FYI the function to send the string to php is :
services.js:
.service('sendToServer', [
'$http',
function ($http) {
'use strict';
this.f = function (dataToSend) {
return $http({
url: 'http://id:pwd@bodlip.com/angular-seed/appendToDb.php',
method: "POST",
data: dataToSend,
headers : {
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
}
});
};
}
])
I thought I should do it in php, and I put this in my php file :
$data[] = $_POST;
//file_put_contents('log.txt', print_r($data, true), FILE_APPEND);
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$data = stripslashes_deep($data);