2013-08-22 48 views
0

我有以下服務定義

app.factory('savedPropertiesService', ['$http', function ($http) { 
    var sessionId = $('input[name=SessionGuid]').val(); 
    var contactId = $('input[name=ContactId]').val(); 
    var savedPropertiesService = {}; 

    savedPropertiesService.getSavedProperties = function() { 
     return $http.get("/Contact/SavedProperties?sessionGuid="+sessionId+"&contactId=" + contactId); 
    }; 

    savedPropertiesService.refreshSavedProperties = function() { 
     return $http.get('/Contact/RefreshSavedProperties?sessionGuid=' + sessionId + '&contactId=' + contactId); 
    }; 

    savedPropertiesService.deleteSavedProperty = function (listingKey) { 
     return $http['delete']('/Contact/DeleteSavedProperty?sessionGuid=' + sessionId + '&contactId=' + contactId + '&id=' + listingKey); 
    }; 

    savedPropertiesService.updateSavedProperty = function (prop) { 
     return $http.put('/Contact/UpdateSavedProperty/', prop); 
    }; 

    return savedPropertiesService; 
}]); 

,它是在我的控制器使用像這樣

$scope.$watch('items', function (newVal, oldVal) { 
    if (_.isEmpty(newVal) || _.isEmpty(oldVal)) return; 
    var prop = difference(newVal, oldVal); 


    savedPropertiesService.updateSavedProperty(prop) 
     .success(function (data) { 
      $scope.status = data; 
     }) 
     .error(function (error) { 
      $scope.status = 'Unable to update saved properties data: ' + error.message; 
     });  
}, true); 

和服務端點(請不要判斷VB)

<HttpPut()> 
Function UpdateSavedProperty(rating As RatingDto) As JsonResult 
    Return Json(ControlLibrary.CS.__PropDetails.ContactPropertiesDataFactory.UpdateSavedProperty(rating), JsonRequestBehavior.DenyGet) 
End Function 

不管我做什麼,永遠達不到JSON.stringify或不是我的MVC3 enpoint並且框架引發異常。 System.ArgumentException:無效的JSON基元。

我甚至只是試圖發佈一個手工製作的對象,看它是否會讓它到達終端,全都無濟於事。

有沒有人有什麼建議可能是錯誤的代碼?

謝謝 斯蒂芬

回答

1

結果我發現我定義的全局變換$ http和它是使用jQuery.param()來編碼。一旦我刪除它,它完美的工作。

var app = angular.module('app', ['ui.select2', 'ui.bootstrap']) 
    .config(['$httpProvider', function ($httpProvider) { 
     delete $httpProvider.defaults.headers.common['X-Requested-With']; 
     $httpProvider.defaults.transformRequest = function (data) { 
      if (data === undefined) { 
       return data; 
      } 
      return $.param(data); 
     }; 
}]);