2016-12-29 484 views
0

目前来自Angular JS控制器,我试图将JSON数据发送到后端服务。但是我有400个错误的请求错误。400(错误请求)错误

从控制器,我试图通过像HTTP服务发送的数据:

shipDataJson.contractNumber=$scope.contractNumber; 
      shipDataJson.orderNumber=$scope.orderNumber; 
      shipDataJson.shipmentNumber=$scope.shipmentNumber; 
      shipDataJson.SCN=$scope.SCN; 
      shipDataJson.sourceSystem=$scope.selectedSrcSystem; 
      shipDataJson.destinationSystem=$scope.selectedDestSystem; 
      shipDataJson.resendFlag='false'; 

但实际上在发送时间JSON是这样的:

{ 
    "contractNumber": "abc", 
    "orderNumber": "der", 
    "shipmentNumber": "faas", 
    "SCN": "fsdafas", 
    "sourceSystem": { 
    "resendFlag": false, 
    "sourceSystem": "arnab" 
    }, 
    "destinationSystem": { 
    "resendFlag": false, 
    "destinationSystem": "swar" 
    }, 
    "resendFlag": "false" 
} 

不要有想法从JSON中删除额外的“resendFlag”字段。

在此先感谢。

+0

我觉得你的东西之前添加。你发布的内容对我来说看起来是正确的。检查某处添加了? –

+0

尝试控制台:'$ scope.selectedSrcSystem'和'$ scope.selectedDestSystem'。可能在这里只是问题。 –

+0

你可以显示这个对象包含什么,“$ scope.selectedDestSystem”。还告诉我们你在哪里真正分配该对象的值 – Vish

回答

0

如果你想删除resendFlag密钥。 只是删除这一行:shipDataJson.resendFlag='false';

+0

嗨吊杆,“destinationSystem”:{ “resendFlag”:假的, “destinationSystem”:“SWAR” } – ArnabDutta

+0

哦,好吧,你都看记录这个? '$ scope.selectedDestSystem' –

+0

嗨Steeve,我想从“destinationSystem”中删除“resendFlag”:{ “resendFlag”:false, “destinationSystem”:“swar” }。 JSON里面有好几次“resendFlag”字段。 – ArnabDutta

0

从JavaScript对象删除属性,你delete他们:

delete shipDataJson.destinationSystem.resendFlag 
+0

angular.js:11706TypeError:无法将undefined或null转换为对象 在ChildScope.sampleModule.controller。$ scope.searchShipment(ShipmentSrchCtrl.js:46) at $ parseFunctionCall(angular.js:12474) at callback(angular。 js:21700) at ChildScope。$ eval(angular.js:14570) at ChildScope。$ apply(angular.js:14669) at HTMLButtonElement。 (angular.js:21705) 在HTMLButtonElement.dispatch(的jquery.js:4430) 在HTMLButtonElement.r.handle(的jquery.js:4116) – ArnabDutta

+0

上面的错误,我在执行时获得。 – ArnabDutta

+0

这是一个单独的问题。调试您的'searchShipment'功能。 – user1620220