Skip to content
Fix Code Error

Uncaught SyntaxError: Unexpected token :

March 13, 2021 by Code Error
Posted By: Anonymous

I am running an AJAX call in my MooTools script, this works fine in Firefox but in Chrome I am getting a Uncaught SyntaxError: Unexpected token : error, I cannot determine why. Commenting out code to determine where the bad code is yields nothing, I am thinking it may be a problem with the JSON being returned. Checking in the console I see the JSON returned is this:

{"votes":47,"totalvotes":90}

I don’t see any problems with it, why would this error occur?

vote.each(function(e){
  e.set('send', {
    onRequest : function(){
      spinner.show();
    },
    onComplete : function(){
      spinner.hide();
    },
    onSuccess : function(resp){
      var j = JSON.decode(resp);
      if (!j) return false;
      var restaurant = e.getParent('.restaurant');
      restaurant.getElements('.votes')[0].set('html', j.votes + " vote(s)");
      $$('#restaurants .restaurant').pop().set('html', "Total Votes: " + j.totalvotes);
      buildRestaurantGraphs();
    }
  });

  e.addEvent('submit', function(e){
    e.stop();
    this.send();
  });
});

Solution

I have just solved the problem. There was something causing problems with a standard Request call, so this is the code I used instead:

vote.each(function(element){                
  element.addEvent('submit', function(e){
    e.stop();
    new Request.JSON({
      url : e.target.action, 
      onRequest : function(){
        spinner.show();
      },
      onComplete : function(){
        spinner.hide();
      },
      onSuccess : function(resp){
        var j = resp;
        if (!j) return false;
        var restaurant = element.getParent('.restaurant');
        restaurant.getElements('.votes')[0].set('html', j.votes + " vote(s)");
        $$('#restaurants .restaurant').pop().set('html', "Total Votes: " + j.totalvotes);
        buildRestaurantGraphs();
      }
    }).send(this);
  });
});

If anyone knows why the standard Request object was giving me problems I would love to know.

Answered By: Anonymous

Related Articles

  • Upvote and Downvote with Backbone, Express and Mongoose
  • Is mootools alternative of jquery + backbone / spine…
  • Sorting A Table With Tabs & Javascript
  • PHP parse/syntax errors; and how to solve them
  • Mithril - Re-sort array of child components after…
  • Backbone.js Backbone.wrapError function
  • How to extract img src, title and alt from html using php?
  • Downloading jQuery UI CSS from Google's CDN
  • Poll is adding multiple votes
  • Reference - What does this regex mean?
  • Why is it common to put CSRF prevention tokens in cookies?
  • How to use Servlets and Ajax?
  • Vue js: How to use a computed property to modify…
  • How to disable a button after clicking a button using vue.js
  • How to highlight a selected row in ngRepeat?
  • Overriding .fetch() works with fake data, errors…
  • What's the difference between eval, exec, and compile?
  • Laravel Eloquent Join vs Inner Join?
  • Unexpected end of JSON input while parsing
  • What is a NullReferenceException, and how do I fix it?
  • How to set dropdown arrow in spinner?
  • npm install error in vue
  • Paper Spinner like in Android
  • Am I paranoid? "Brutally" big Polymer website after…
  • Getting a count of objects in a queryset in django
  • How do I return the response from an asynchronous call?
  • Using one iron-ajax element for multiple requests
  • Rails params explained?
  • Understanding PrimeFaces process/update and JSF…
  • during wct test: Failed to load resource: the server…
  • commandButton/commandLink/ajax action/listener…
  • For-each over an array in JavaScript
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
  • What is the proper type for a request handler of a…
  • Vue pwa with firebase cloud messaging not working properly
  • TypeError: '
  • Best practice for REST token-based authentication…
  • HTTP 415 unsupported media type error when calling…
  • Decode JSON with unknown structure
  • What are the undocumented features and limitations…
  • How to get the promise value in reactjs?
  • How to filter a RecyclerView with a SearchView
  • Sort table rows In Bootstrap
  • Manually adding a Userscript to Google Chrome
  • Selenium using Java - The path to the driver…
  • How does PHP 'foreach' actually work?
  • Angular: Can't find Promise, Map, Set and Iterator
  • Spinner is not defined in Ladda with RequireJS
  • Asking the user for input until they give a valid response
  • Is there any "font smoothing" in Google Chrome?
  • Is it possible to apply CSS to half of a character?
  • Can't perform a React state update on an unmounted component
  • Ukkonen's suffix tree algorithm in plain English
  • "Body not assignable to class" using ActiveMQ…
  • What is the scope of variables in JavaScript?
  • How can I integrate javascript hot reload into…
  • Aurelia with Typescript and async functions: this is…
  • Type error: Argument 2 passed to Controller::show()…
  • Reactive declarations seems not work? Or am I using…
  • Polymer 1.0 services issue
  • Binding a Backbone Model to a Marionette ItemView -…
  • Unable to display translated text on text view
  • Usage of __slots__?
  • Vue.js progress bar
  • Java Bubble Sort method for Object's fields
  • How to refactor Node.js code that uses…
  • data.table vs dplyr: can one do something well the…
  • How to detect Safari, Chrome, IE, Firefox and Opera browser?
  • next js redux-observable persistent auth token using cookie
  • What does "Fatal error: Unexpectedly found nil while…
  • jQuery Mobile: document ready vs. page events
  • Use a content script to access the page context…
  • How to properly add cross-site request forgery…
  • how to integrate selenium driver for chrome and…
  • Postgres - connect three tables and use aggregate…
  • What is an optional value in Swift?
  • Backbone (sync) update event
  • Grouped bar plot in ggplot
  • MySQL LAG/LEAD issue
  • How to assign ranking on objects based on a value in…
  • Ember Data belongsTo async relationship omitted from…
  • Smart way to truncate long strings
  • Using a redux store with react-navigation
  • PolymerJS: Iron-Ajax - How to Bind Token to Headers…
  • Run chrome in fullscreen mode on Windows
  • Identifying and solving…
  • Getting [object Object] instead of object in React
  • Trying to create a custom polymer component using ag-grid
  • Show/hide 'div' using JavaScript
  • JWT authentication for ASP.NET Web API
  • What is causing this broken animation/transition in…
  • Polymer dropdown data binding with AJAX response
  • No visible cause for "Unexpected token ILLEGAL"
  • Backbone Collection.fetch gives me Uncaught…
  • Font awesome spinner not spinning
  • How to change spinner text size and text color?
  • vue router.push : TypeError: onComplete is not a function
  • Spinner not working vue.js
  • Getting Chrome to prompt to save password when using…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to convert integer to string in C?

Next Post:

How to add an image to a JPanel?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error