$ http.post始终返回错误

时间:2014-03-03 22:48:54

标签: jquery asp.net-mvc angularjs

我在js文件中有以下代码用于数据访问:

GroupsApp.factory('availableQuestionRepository', function ($http, $q) {
var factory = {};

factory.get = function (groupID) {
        var deferred = $q.defer();
        var url = "questiongrouping/AvailableQuestions/";
        url = url.concat(groupID)
        $http.get(url).success(deferred.resolve).error(deferred.reject);
        return deferred.promise;
    }

factory.save = function (availableQuestions) {

    var deferred = $q.defer();
    $http.post("questiongrouping/PostQuestions", availableQuestions)
        .success(function () { deferred.resolve(); })
        .error(function () { deferred.reject(); });
    return deferred.promise;
};

return factory;
})

控制器如下:

GroupsApp.controller("availableQuestions", function ($scope, availableQuestionRepository, msgBus) {
$scope.$on('GroupChanged', function () {
    loadAvailableQuestions();
});

$scope.save = function (aq) {
    availableQuestionRepository.save(aq).then(
        function () { alert("sucess") },
        function () { alert("error") });
}

function loadAvailableQuestions() {
    availableQuestionRepository.get(msgBus.groupID).then(function (AvailableQuestions) { $scope.availableQuestions = AvailableQuestions });

}
});

MVC控制器代码如下:

Function PostQuestions(result As List(Of QuestionRO)) As ActionResult
    Return New HttpStatusCodeResult(System.Net.HttpStatusCode.OK)
End Function

为什么当我在Chrome中转到页面时,它会一直弹出错误警报?我已经在IE 10中尝试了它,它会弹出成功警告框。

1 个答案:

答案 0 :(得分:0)

我终于找到了导致我问题的原因。问题包括标签:

<form class="form">

</form>

删除此标记后,提交数据的按钮工作正常。

相关问题