Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught SyntaxError: Unexpected token o [duplicate]

I have a web app I am working on:

$("#post").click(function () {

    var u = $('#u').val();
    var j = $('#j').val();

    $.post("http://www.myweb.php", {
            u: u,
            j: j
        })
        .done(function (data) {


            var obj = jQuery.parseJSON(data);
            alert(obj.status );
            //alert("Data Loaded: " + data);
        });

});

When it tries to retrieve the JSON I get:

Uncaught SyntaxError: Unexpected token o
like image 698
Mike Avatar asked Jul 03 '15 16:07

Mike


People also ask

What does uncaught SyntaxError unexpected token mean?

The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site's code referring to an asset that is no longer available. Most commonly, this is due to a filename change in assets generated during your build.

How do I fix unexpected token in JSON error?

The "Unexpected token u in JSON at position 0" error occurs when we pass an undefined value to the JSON. parse or $. parseJSON methods. To solve the error, inspect the value you're trying to parse and make sure it's a valid JSON string before parsing it.

How do you find uncaught SyntaxError unexpected identifier?

To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.


1 Answers

You don't have to call .parseJSON(). Your response has already been parsed. You're getting that error because the object you pass to jQuery.parseJSON() is being converted to the string "[object Object]". The unexpected token is that "o" in "object".

like image 50
Pointy Avatar answered Oct 17 '22 02:10

Pointy