Angularjs:在请求中发送适合的json属性

时间:2015-05-14 16:20:19

标签: javascript json angularjs

有没有告诉angularjs($ http服务)在进行HTTP POST时不要将某些属性发送到Json对象?

假设我有一个像这样的对象定义:

 $scope.toBeSaved = { id : 1,
   name: myname,
   someAttributeTobeFiltered : 1233459,   
 }

someAttributeTobeFiltered来电期间,有没有过滤$http.post(url,$scope.toBeSaved)不发送?

提前致谢

2 个答案:

答案 0 :(得分:1)

因此,使用_.omit方法可以执行以下操作:

    $soap_client = new SoapClient("https://ifs-uat.ca.equifax.com/uru/soap/ut/canadav2?wsdl");
    $functions = $soap_client->__getFunctions();
    $soap_client->__setSoapHeaders($this->generateWSSecurityHeader($username, $password, "PasswordText"));

    $all_names = array('FirstName'=>"PERFUME",
                       'LastName'=>"TESTSWEET");

    $all_addresses = array('AddressLine'=>"109 ALBERT ST NE",
                           'City'=>"AIRDRIE",
                           'Province'=>"AB",
                           'PostalCode'=>"T4B0R5"
                           );

    $hybrid_address = array('HybridAddress'=>$all_addresses);
    $identity = array('Name'=>$all_names,
                      'Address'=>$hybrid_address
                      );

    $language = array('Language'=>'English');

    $initial_request = array('Identity'=>$identity,
                             'ProcessingOptions'=>$language
                             );

    try{
        $test = $soap_client->__soapCall('startTransaction', array('InitialRequest'=>$initial_request));
    }
    catch(SoapFault $fault){
        die("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})");
    }

    echo $soap_client->__getLastRequest();

答案 1 :(得分:1)

这将删除通过$ http发出的每个请求的给定属性。

.config(['$httpProvider', function($httpProvider )
{
    $httpProvider.defaults.transformRequest = [function(data)
    {
        if(typeof data === "object")
        {
            var toSend = angular.copy(data);
            delete toSend.someAttributeTobeFiltered;
            return toSend;

        }
        else{
            return data;
        }
    }];

}]);