AngularJS: Encountering an unexpected identifier while trying to make a POST

I'm facing an issue with my http POST request in AngularJS. When I make the function call to $http, I receive a SyntaxError: Unexpected identifier. The unexpected identifier is pointing to the line url: 'rating-add' within my $http call. ‘rating-add’ is a named URL, so it's confusing why it's not recognizing it. Here 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 here are the urls in 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'),
]

Answer №1

One thing you need to fix is the missing comma in the code below:

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

You should update it to look like this:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method to obtain the keycode for a key combination in JavaScript?

$(document).on('keydown', function(event) { performAction(event); event.preventDefault(); }); By using the code above, I am successful in capturing the keycode for a single key press. However, when attempting to use a combin ...

Steps for saving both checked and unchecked checkbox values in Firebase

I have a set of objects that I am using as initial data in my Ionic 3 application: public interests = [ { name: 'Travel', checked: false }, { name: 'Animals', checked: false }, { name: 'Theatre', checked: false ...

Failure to pass a variable declared within a function to another JavaScript file running simultaneously

After combing through numerous posts on Google and Stack Overflow, I am still unable to pinpoint why this particular issue persists. This case involves 2 HTML files and 2 JS files (explanations provided below in text following the code snippets). 1) inde ...

The value control input does not get properly updated by ngModelChange

Having difficulty updating an input as the user types. Trying to collect a code from the user that follows this format: 354e-fab4 (2 groups of 4 alphanumeric characters separated by '-'). The user should not need to type the '-', as it ...

Access the document utilizing the CSV module in Django with universal-newline functionality enabled

Currently facing an issue where I am attempting to retrieve a model.filefield in Django to read and process a CSV file in Python with the csv module. Surprisingly, it is functioning correctly on Windows, but on Mac, it is throwing the following error: ...

directive scope is not functioning

Looking to incorporate an input element into my Google Map, I've written the code below: app.directive('GooglePlaceAutoComplete', function() { return { restrict:'AEC', replace: true, scope: { myMap:&ap ...

Is it possible to save the video title as a variable using YTDL-core?

Is there a way to store the video title as a global variable in JavaScript? ytdl.getBasicInfo(videoURL, function(err, info) { console.log(info.title) }); I have been trying various methods but I am unable to successfully define a variable to hold the v ...

How come this variable isn't recognized as 0 even though the debugger is indicating otherwise?

I am currently working on a React component that receives the total number of reviews as a prop. In cases where the number of reviews is 0, I intend to display an element indicating <div>No reviews yet.</div> If there are reviews available, I ...

What are the advantages of passing state from child components up in React?

I have been attempting to update the state within the App component from a child component, but I am concerned that this approach may cause issues later in my application. I've experimented with passing down the setFunction to the child components an ...

How to retrieve the content/value from a textfield and checkbox using HTML

I'm encountering an issue with my HTML code where I am unable to extract data from the HTML file to TS. My goal is to store all the information and send it to my database. Here is a snippet of the HTML: <h3>Part 1 : General Information</h3 ...

Troubleshooting slow performance in AngularJS ui-select

Currently, I am utilizing the UI Select control within my application (source - https://angular-ui.github.io/ui-select/). Unfortunately, it is experiencing a significant performance issue when populated with over approximately 2000 items. I have also exp ...

After receiving a data token from the server in one controller, how can I efficiently utilize that token in a different AngularJS controller?

In my adminSearchCtrl controller, I am receiving data from the server in the form of a token and want to pass that token to another controller named "adminViewCtrl". How can I achieve this? adminSearchCtrl.js $scope.getUserDetails = function(selectedUser ...

Invalid URL path being fetched by DJango FileSystem

My form includes both an ImageField and a FileField. While the files are successfully uploading to the correct folders, I'm encountering an issue when trying to retrieve the URL for display on the screen. fs_img = FileSystemStorage(location='me ...

What is the reason for labels appearing inside select boxes?

Can someone help me understand why my select box label is displaying inside the select box? For example, when I am not using react-material-validator it looks like this: https://codesandbox.io/s/5vr4xp8854 When I try to validate my select box using the r ...

Can regular expressions be employed to match URLs with $urlRouterProvider in AngularJS?

My goal is to create a regex expression that matches all strings in my routing config which do not start with "/pt/" or "/en/". Additional text may be present in these strings. This is what I have so far: $urlRouterProvider.when('^(?!/(pt|en)/).*&ap ...

The way in which elements are displayed is determined by the chosen value in React

As a new developer in react, I am looking to render different HTML elements based on the selected value. Additionally, I am interested in the possibility of sending POST data from the selected HTML to a Django model. Below is the react JS code I have been ...

What is the process for setting up an automatic submission for the "Search" feature?

My Perspective: @using (Html.BeginForm()) { <p id="a"> Search for VCMEMBRE/VCPARENT: @Html.TextBox("SearchString") <input type="submit" name="searchType" value="Find!" /> </p> } My Handler: public ActionResult ...

Encountering a problem during the installation process of Sails.js with Angular.js

I'm currently working with a Sails.js backend and AngularJS frontend. After running npm install, the following error is displayed: npm ERR! peerinvalid The package grunt does not satisfy its siblings' peerDependencies requirements! npm ERR! peer ...

Disabling the select2 function does not function as intended

Currently, I am on version 3.5.1 and have attempted to toggle between enable: false and disable: true However, neither option appears to be functioning correctly. Below is a snippet of the relevant code: var select2Node = $element[0].firstChild; ...

The Vue3 counterpart of vNode.computedInstance

I'm currently in the process of upgrading my app from Vue2 to Vue3, but I've hit a roadblock when it comes to dealing with forms. For my form elements, such as FormInput, FormTextArea, and FormCheckbox, I have been using Single File Components ( ...