Hello!
Problem processing an AJAX request to the server
"SyntaxError: Unexpected token <in JSON at position 0"
AJAX code:
$.ajax({ url: this.props.url, dataType: 'json', success: function(data) { var json = JSON.parse(data) this.setState({data: json}); }.bind(this), error: function(xhr, status, err, data) { console.error(this.props.url, status, err.toString()); }.bind(this) }); },
Server code:
var http = require('http'); var fs = require("fs"); http.createServer(function (request, response) { var req = request.url; fs.readFile(req, function (err, data) { response.writeHead(200, { 'Content-Type': 'application/json', "Access-Control-Allow-Origin": "*" }); response.write(data); response.end(); }); }).listen(3000);