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
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.
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.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With