0

I am having trouble with my http POST request in AngularJS. The function call to $http is giving me a SyntaxError: Unexpected identifier. The unexpected identifier is referring to the line url: 'rating-add' in my $http call. 'rating-add' is a named url, so I don't know why it doesn't know this. This is the template:

<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>

And the 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'),
]

1 Answer 1

2

You are missing ,. change this:

$http({
          method: 'POST'
          url: 'rating-add'
          data: data
        });

into:

$http({
      method: 'POST',
      url: 'rating/add/',
      data: data
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Shouldn't your URL be /rating/add rather than rating-add?
@ke4ktz is right. you defined the path to the resource as url(r'rating/add/$', RatingCreate.as_view(), name='rating-add')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.