2015-11-04 74 views
1

我很難處理空值。每當我將JSON發送到服務器時,前端中的所有null值都以字符串形式變爲"null"。我該如何處理?JSON中的NULL/AngularJS(前端)和Laravel(後端)中的數組

AngularJS:在我的控制器中。在我的控制器:我是從一種形式使用NG文件上傳插件https://github.com/danialfarid/ng-file-upload/wiki/PHP-Example

$scope.saveNewDocument = function(){ 
    var formAttachments = Upload.upload({ 
     url: appServer.baseURL + appServer.api.generalDocuments, 
     method: 'POST', 
     file: $scope.formData.formAttachments, 
     sendFieldsAs: 'form', 
     fields: $scope.formData // $scope.formData is ng-model in view forms 
    }).then(function(success){ 
     //some codes 
    }, function(error){ 
     console.log(error); 
    }); 
}; 

Laravel發送值。

public function store(Request $request) 
    { 

     $request = $request->all(); 

     //if I get values from request. All null becomes "null" 

    } 
+0

請添加您的代碼。 –

+0

@TarunDugar請檢查我的代碼。謝謝。 – philxtian

回答

0

因爲我們還沒有提供任何代碼,我不知道究竟你的問題,但假設解決PHP這個問題(此標記爲)你可以寫一個簡單的if語句和檢查發送前的數據如下:

if($var==null) 
    $var=0;