0

I'm currently using the Algolia JS API but for some reason I keep randomly getting the following error in console:

UncaughtUncaught syntax error unexpected token u in JSON at position 0

My current code looks like this:

    var params  = {
        hitsPerPage: 10,
        page: 0,
        facets: '*'
    }   
    index.search('some search term', params, function load_search_products_callback(err, content) {
        console.log(content);
    });

The problem is that the error occurs before the console.log(content) part of the code is run, so I'm unable to actually what the problem is or where it's happening.

halfer
  • 19,824
  • 17
  • 99
  • 186
user2028856
  • 3,063
  • 8
  • 44
  • 71

1 Answers1

2

From looking at your code I can predict it is a JS code.

UncaughtUncaught syntax error unexpected token u in JSON at position 0 occur when you pass undefined to JSON.parse as an argument.

var a = undefined; JSON.parse( a );

This can be the issue in your code. You need to figure out where this is happening in your code.

I hope that'll help

Sparsh Pipley
  • 451
  • 8
  • 22
  • 1
    `From looking at your code I can predict it is a JS code` - the [javascript] tag was my first clue that the code is javascript – Jaromanda X Jan 17 '17 at 05:18