簡體   English   中英

使用序列化,並刪除反斜杠轉義的斜杠

[英]Use serialize, and remove backslashes escaping slashes

我正在序列化一個字符串以能夠發送到php腳本,但是該函數將字符串保留為/而不是/。 我想從字符串中刪除\\

你能幫助我嗎 ?

我使用的功能:

$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("&");
}

我正在使用此功能發送到文件:

$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 !')
        });
}

僅供參考,將字符串發送到php的函數是:

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'
                }
            });
        };
    }
])

我以為我應該在php中執行此操作,並將其放在我的php文件中:

 $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);

我將此行添加到我的代碼中:

$line = str_replace('\\', '', $line);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM