solved- problems with Uncaught SyntaxError: Unexpected token ) - richb201 - 03-23-2018
This is a little embarassing. I had my javascript code almost working, fooled with it a little too much trying to get the xhr working. I am using notepad as my editor and thus it has no syntax checking. Additionally I have a really hard time with the inline call back functions. I am trying to run this code in the Chrome debugger and I keep getting "unexpected token )" at the line right after the sendResponse(token). Can anyone see where my syntax is screwed up. Does anyone know of a javascript editor that helps with syntax? Are there any better tools for working with javascript?
Code: ////var iToken;
//var userInfo;
var email;
var myArray={};
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.task =="login"){
// remove_token(); //get rid of old token
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
currentSessionAccessToken=token;
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token);
x.onload = function() {
if (x.readyState=200)
{
send_to_backend();
};
x.send();
sendResponse(token);
}); <<this is the line with the uncaught syntax error
}
chrome.identity.getProfileUserInfo(function(userInfo) {email=userInfo.email} ) ;
sendResponse( {'email': email});
navigator.geolocation.getCurrentPosition(function(position) {
//alert(position.coords.latitude);
//alert(position.coords.longitude);
myArray["lat"]=position.coords.latitude;
myArray["long"]=position.coords.longitude;
});
});
RE: problems with Uncaught SyntaxError: Unexpected token ) - Paradinight - 03-23-2018
(03-23-2018, 04:06 PM)richb201 Wrote: This is a little embarassing. I had my javascript code almost working, fooled with it a little too much trying to get the xhr working. I am using notepad as my editor and thus it has no syntax checking. Additionally I have a really hard time with the inline call back functions. I am trying to run this code in the Chrome debugger and I keep getting "unexpected token )" at the line right after the sendResponse(token). Can anyone see where my syntax is screwed up. Does anyone know of a javascript editor that helps with syntax? Are there any better tools for working with javascript?
Code: ////var iToken;
//var userInfo;
var email;
var myArray={};
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.task =="login"){
// remove_token(); //get rid of old token
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
currentSessionAccessToken=token;
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token);
x.onload = function() {
if (x.readyState=200)
{
send_to_backend();
};
x.send();
sendResponse(token);
}); <<this is the line with the uncaught syntax error
}
chrome.identity.getProfileUserInfo(function(userInfo) {email=userInfo.email} ) ;
sendResponse( {'email': email});
navigator.geolocation.getCurrentPosition(function(position) {
//alert(position.coords.latitude);
//alert(position.coords.longitude);
myArray["lat"]=position.coords.latitude;
myArray["long"]=position.coords.longitude;
});
});
editor (free):
- atom https://atom.io/
- visualstudio code https://code.visualstudio.com/
- eclipse http://www.eclipse.org/downloads/eclipse-packages/
- netbeans https://netbeans.org/ / https://netbeans.apache.org/ (half dead)
editor (not free):
- phpstorm or webstorm https://www.jetbrains.com/webstorm/ https://www.jetbrains.com/phpstorm/
RE: problems with Uncaught SyntaxError: Unexpected token ) - Paradinight - 03-23-2018
Code: ////var iToken;
//var userInfo;
var email;
var myArray={};
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.task =="login"){
// remove_token(); //get rid of old token
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
currentSessionAccessToken = token;
var x = new XMLHttpRequest();
x.open('GET', 'https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=' + token);
x.onload = function () {
if (x.readyState == 200) {// should be == or ?
send_to_backend();
}
x.send();
sendResponse(token);
}; //
}) // missing } :)
}
chrome.identity.getProfileUserInfo(function(userInfo) {email=userInfo.email} ) ;
sendResponse( {'email': email});
navigator.geolocation.getCurrentPosition(function(position) {
//alert(position.coords.latitude);
//alert(position.coords.longitude);
myArray["lat"]=position.coords.latitude;
myArray["long"]=position.coords.longitude;
});
});
RE: solved- problems with Uncaught SyntaxError: Unexpected token ) - richb201 - 03-23-2018
Thanks. I found it. Now back to my real problem!
|