2016-12-29 329 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