我在AngularJS中遇到了我的http POST请求。对$ http的函数调用给了我一个SyntaxError:意外的标识符。意外的标识符是指行url:' rating-add'在我的$ http电话中。 '等级加'是一个名字网址,所以我不知道它为什么不知道这个。这是模板:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http){
$scope.ratings = [];
var data = $scope.myForm = {beer_name:'', score:'', notes:'', brewer:''};
$scope.buttonClick = false;
$scope.is_clicked = function() {
$scope.buttonClick=true;
console.log($scope.buttonClick)
}
$scope.submit_to_form = function() {
$http({
method: 'POST'
url: 'rating-add'
data: data
});
}
})
</script>
和urls.py:
from django.conf.urls import url
from django.contrib import admin
from ratings.views import home, RatingCreate, delete, edit
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', RatingCreate.as_view(), name='rating-home'),
url(r'rating/add/$', RatingCreate.as_view(), name='rating-add'),
url(r'rating/delete/(?P<row_id>[0-9]+)/$', delete , name='rating-delete'),
url(r'rating/edit/(?P<row_id>[0-9]+)/$', edit , name='rating-edit'),
]
答案 0 :(得分:2)
您缺少,
。改变这个:
$http({
method: 'POST'
url: 'rating-add'
data: data
});
成:
$http({
method: 'POST',
url: 'rating/add/',
data: data
});