SyntaxError: Unexpected token F, when using $ and restangular post


We are using angular in our current project and we are doing API calls with Restangular. Suddenly i started to get error when doing a post to a certain endpoint.

the post was something like:'aaa').post('bbb', data)
  .then((response) => {
  }, (err) => {

And the log was this:

SyntaxError: Unexpected token F

After a while I gave up and tried to use angular $http service.

  method: 'POST',
  url: '/aaa/bbb',
  data: data
}).then(function successCallback(response) {
  }, function errorCallback(response) {

and the log:

SyntaxError: Unexpected token F

After that i started to get desperate and did a post with jQuery.ajax

  type: 'POST',
  data: data,
  contentType: 'application/json; charset=utf-8',
  success: function(s) {
    console.log('jquery success');
  error: function(e) {
    console.log('jquery error');
  complete: function(c) {
    console.log('jquery complete');

And the log when using jquery.ajax:

Object {readyState: 4, responseText: "Fatal error: actual error message here", status: 200, statusText: "OK"}
jquery error

Finally got something! We are using drupal as our backend and one of the modules was not enabled.
I am just wondering why did restangular and $http fail to give proper error message.


The responses produced by Restangular and the $http module are identical to the response that would be received from the JSON module. For example:


produces the error:

Uncaught SyntaxError: Unexpected token F

The response from jQuery is the raw response data from the server without the application of JSON.parse.

Answered By – gnerkus

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.