Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django Angular js无法使用$http.post发布数据_Django_Angularjs_Http Post - Fatal编程技术网

Django Angular js无法使用$http.post发布数据

Django Angular js无法使用$http.post发布数据,django,angularjs,http-post,Django,Angularjs,Http Post,我有一个angular应用程序,试图将一些元素发布到数据库中。这里我使用的是一个模式,其中我检查了一些课程,以便使用$http.post发布已检查的课程。以下是发布数据的函数: $scope.ok = function () { //$scope.subcategory.subcategory2 = []; for(var i = 0; i < $scope.selectedCourses.length; i++){

我有一个angular应用程序,试图将一些元素发布到数据库中。这里我使用的是一个模式,其中我检查了一些课程,以便使用
$http.post
发布已检查的课程。以下是发布数据的函数:

$scope.ok = function () {
              //$scope.subcategory.subcategory2 = [];
                for(var i = 0; i < $scope.selectedCourses.length; i++){
                    debugger
                  //$scope.subcategory.subcategory2.push({course: $scope.selectedCourses[i], term:"--",credit:"--",grade:"--"});
                  var variablesToSend = {
                                        "student": 2773951,
                                        "course_name": $scope.selectedCourses[i].course.course_name,
                                        "title": $scope.selectedCourses[i].course.title,
                                        "credit": 3,
                                        }
                    $http.post('/api/studentplannedcredit/', variablesToSend).then(function(response){
                        console.log(response);
                        //alert('post added');
                        //document.location.reload(true);

                    }, function(response){
                        console.log(response);
                        alert('Unable to add Course');
                    });             
                }
                $modalInstance.close();
            };
$scope.ok=函数(){
//$scope.subcategory.subcategory 2=[];
对于(变量i=0;i<$scope.selectedCourses.length;i++){
调试器
//$scope.subcategory.subcategory 2.push({course:$scope.selectedCourses[i],术语:“--”,学分:“--”,成绩:“--”);
var variablesToSend={
“学生”:2773951,
“课程名称”:$scope.selectedCourses[i]。课程。课程名称,
“title”:$scope.selectedCourses[i].course.title,
“信用”:3,
}
$http.post('/api/studentplannedcredit/',variablesToSend)。然后(函数(响应){
控制台日志(响应);
//警报(“添加后”);
//文档。位置。重新加载(true);
},功能(回应){
控制台日志(响应);
警报(“无法添加课程”);
});             
}
$modalInstance.close();
};
我在这里遇到的错误是,当我调用函数时,它会给我以下错误:

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.2.8/$rootScope/inprog?p0=%24digest
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:78:12
    at beginPhase (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:12262:15)
    at Scope.$get.Scope.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:12048:11)
    at Scope.$delegate.__proto__.$apply (<anonymous>:855:30)
    at HTMLDivElement.<anonymous> (http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.min.js:8:20385)
    at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:2612:10
    at forEach (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:309:20)
    at HTMLDivElement.eventHandler (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:2611:5)
    at http://127.0.0.1:8000/static/js/app.js:161:7
    at deferred.promise.then.wrappedErrback (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:10952:78) angular.js:9413
(anonymous function) angular.js:9413
$get angular.js:6832
$get.Scope.$apply angular.js:12051
$delegate.__proto__.$apply VM437152:855
(anonymous function) ui-bootstrap-tpls-0.10.0.min.js:8
(anonymous function) angular.js:2612
forEach angular.js:309
eventHandler angular.js:2611
(anonymous function) app.js:161
deferred.promise.then.wrappedErrback angular.js:10952
deferred.promise.then.wrappedErrback angular.js:10952
(anonymous function) angular.js:11078
$get.Scope.$eval angular.js:11949
$get.Scope.$digest angular.js:11775
$delegate.__proto__.$digest VM437152:844
$get.Scope.$apply angular.js:12055
$delegate.__proto__.$apply VM437152:855
done angular.js:7837
completeRequest angular.js:8020
xhr.onreadystatechange angular.js:7976
错误:[$rootScope:inprog]$digest已在进行中
http://errors.angularjs.org/1.2.8/$rootScope/inprog?p0=%24摘要
在http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:78:12
初期(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:12262:15)
范围为$get.Scope.$apply(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:12048:11)
在作用域中。$delegate.\uuuu proto.$apply(:855:30)
在HTMLDEVELENT。(http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.10.0.min.js:8:20385)
在http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:2612:10
在弗雷赫(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:309:20)
在htmldevelment.eventHandler(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:2611:5)
在http://127.0.0.1:8000/static/js/app.js:161:7
在deferred.promise.then.wrappederback(http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.js:10952:78)www.js:9413
(匿名函数)angular.js:9413
$get angular.js:6832
$get.Scope.$apply angular.js:12051
$delegate.\uuuu proto.$apply VM437152:855
(匿名函数)ui-bootstrap-tpls-0.10.0.min.js:8
(匿名函数)angular.js:2612
forEach.js:309
eventHandler.js:2611
(匿名函数)app.js:161
deferred.promise.then.wrappederback.js:10952
deferred.promise.then.wrappederback.js:10952
(匿名函数)angular.js:11078
$get.Scope.$eval angular.js:11949
$get.Scope.$digest.js:11775
$delegate.\uuuu proto.$digest VM437152:844
$get.Scope.$apply angular.js:12055
$delegate.\uuuu proto.$apply VM437152:855
完成。js:7837
completeRequest.js:8020
xhr.onreadystatechange angular.js:7976

我不确定这是您的示例中的某个地方,还是您在其他地方做错了什么。 下面是一个工作的例子,一个职位的角度

var config = {
    method: 'POST',
    url: '/api/studentplannedcredit/',
    data: variablesToSend 
};


$http(config)
.success(function(data, status, headers, config) {
    console.log(data);
})
.error(function(data, status, headers, config) {
    console.log(data);
});

PS:不要为每个循环发帖。。那将严重打击API。。首先收集数据,然后只发送一篇帖子。

我假设这里的问题是$modalInstance

试着跑而不跑

$modalInstance.close();

这与您的
$http.post
无关。您正在代码中的某个地方调用
$digest
$apply
,而摘要周期已经在进行中,这段代码很难分辨,可能是其他地方。但可能与将帖子包装在循环中有关,我会将您的$http.post调用包装在$q.all()中,然后您可以使用单数.then()。