2013-08-22 51 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); 
     }; 
}]);