ajax - SyntaxError: Unexpected token u, not parsing -


i'm trying send post request so:

$.ajax({    type: "post",    url:"/game/register",    data: {"user": username},    success: function(){console.log("success");},    datatype: 'json' }); 

and i'm receiving on there server so:

var jsonstring = ''; req.setencoding('utf8');  req.on('data', function (data) {    jsonstring += data; });  req.on('end', function () {    console.log(jsonstring);    reqdata = json.parse(jsonstring);    //console.log(reqdata);    respond(200, json.stringify(reqdata)); }); 

i'm getting following error when try parse.

syntaxerror: unexpected token u 

it seems build string fine because can print it, not convert json. ideas?

from error i'd json.parse getting that's not json syntax. maybe 'undefined' ? add console message around line,

jsonstring += data 

check type of data. string?

edit: based on reply in comment, data not json, no wonder json.parse() fails. json syntax looks this:

{"user":"whateverusernameis"} 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -