First, I've read many posts here but haven't found the issue in my own code, including this one $.ajax and JSONP. ParseError and Uncaught SyntaxError: Unexpected token :
I'm building a Safari extension and need to post/get to my server and handle the response. Safari is throwing this error:
SyntaxError: Unexpected token ':'
and this message
"handle was not called"
where 'handle' is the callback in this Extension code:
var server="http://localhost:3001/api/login";
$.ajax({
type : "GET",
url : server,
data: {"something" : "else"}
dataType: 'jsonp',
jsonp:false,
jsonpCallback: 'handle',
success: function(data, text){
var json = $.parseJSON(data);
console.log(json)
},
error: function (request, status, error) {
console.log(error );
}
});
and the Express.js (2.5.5) code is:
//in the config
app.set( "jsonp callback", true )
app.all('/', function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.get('/api/login', function(req, res){
res.json(
{
"success": {"that":"this"}
}
);
});
NOTES: I've tried res.jsonp, setting content types, etc, with same response. I've learned a TON about CORS and Ajax in the process, but my eyes are clearly bleary. Clicking my heels three times hasn't helped either.
Clues? Thanks!