question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax error in ajax response '=>'

See original GitHub issue

On iPhone (Safari, Chrome) and on OSX Safari I get the following error in console:

SyntaxError: Unexpected token ‘>’

Pointing to this line:

this.$http.patch('/api/things/' + id, thing, { method: 'PATCH'}).then((response) => {

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
LinusBorgcommented, Aug 21, 2016

the example uses ES6 syntax (namely arrow functions), no one is forcing you to use it this way and ES6 is not required to use vue-resource.

Concerning the example, instead of this:

.then((response) => { …

simply do this:

.then( function (response) { …

0reactions
LinusBorgcommented, Aug 22, 2016

does it have any implications on how the returned data is handled?

I thought no, but it turns out yes.

  • No, the second example should work, because vue-resource binds the callback to this. At least it did last time I used it with a normal function callback. Seems it doesn’t anymore.
  • So yes, you have to func the function to the current scope:
.then(function (response) {
 ...
}.bind(this))

… or use a closure.

Arrow functions keep the this context of where they are called automatically, so they kind of do the above for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - AJAX using jQuery - Syntax Error? - Stack Overflow
Thus, I've created a DOM text-node of your response, and append that instead of just the text string. Note that the edit is...
Read more >
ajax request url syntax error in javascript file - Using Django
I have a problem with Ajax Request URL syntax in the Javascript File. When the code is in the html file everything is...
Read more >
AJAX call does not seem to work. Receiving 'Uncaught ...
Any help is much appreciated. This is an AJAX call to a shoretel VoIP server internally. I receive 'Uncaught SyntaxError: Unexpected token ILLEGAL...
Read more >
console reports syntax error for valid json fetched via jquery.ajax
Since the content type is json and not xml, the xml parser cannot parse it and it results in "Syntax error" being written...
Read more >
How to Fix SyntaxError: Unexpected token < in JSON at ...
In this case the error is thrown when response.json() tries to run and fails to parse the data from the server as JSON....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found