I am trying to execute the following function using async/await, but I getting the following error:
Uncaught SyntaxError: Unexpected token function
Using the following code:
async function getCsrfToken() {
let token = '';
await $.get(domain + '/mobile/token', result => {
token = result;
});
return token;
}
My Editor isn't complaining about the syntax, but Chrome within Crosswalk is complaining about it. Am I doing something wrong or do I need to do something within crosswalk?
Related
I'm trying to set up a Back4App backend in a react native expo 45 app. I keep getting a
[Unhandled promise rejection: ReferenceError: Can't find variable: indexedDB]
warning related to the async-storage and Parse import.
import AsyncStorage from "#react-native-async-storage/async-storage";
const Parse = require("parse/react-native.js");
Parse.setAsyncStorage(AsyncStorage);
The warning points to a function in
node_modules\parse\node_modules\idb-keyval\dist\compat.cjs
function createStore(dbName, storeName) {
var dbp = safariFix__default['default']().then(function () {
var request = indexedDB.open(dbName);
request.onupgradeneeded = function () {
return request.result.createObjectStore(storeName);
};
return promisifyRequest(request);
});
return function (txMode, callback) {
return dbp.then(function (db) {
return callback(db.transaction(storeName, txMode).objectStore(storeName));
});
};
}
I find almost no results with searches so I don't even know where to begin troubleshooting. Am I missing something or can this just be ignored?
The problem is in Parse#3.4.2
I reverted back to Parse#3.4.0 and all is working again for now.
I am getting error:
Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=SyntaxError: Unexpected end of script, WKJavaScriptExceptionColumnNumber=0, WKJavaScriptExceptionSourceURL=file:///Users/rb/Library/Developer/CoreSimulator/Devices/675AC846-408B-486C-AE49-3F2187728698/data/Containers/Bundle/Application/7D63B436-AD1F-4CE5-857D-698EE857CC7D/flockmail.app/Frameworks/RichEditorView.framework/rich_editor.html, NSLocalizedDescription=A JavaScript exception occurred}
when executing following Javascript function using evaluateJavaScript.
/*jshint esversion: 6 */
function replaceLinkURL(jsonData) {
var userData = JSON.parse(jsonData);
var div = [...document.querySelectorAll('div.class1')].filter(function(el) {
return !el.querySelector('blockquote');
});
var correctDiv = div.filter(function(el) {
return !el.getElementsByClassName('.classLink').length;
});
correctDiv.forEach(function(el) {
el.getElementsByClassName('.classLink').href = userData.link;
});
}
Being new to Javascript, I can't figure out the issue, also I validated Javascript and its correct. There is no other handling I did in WKWebview for this.
I have made a small vanilla javascript code to fetch api but it is throwing the error "Uncaught (in promise) SyntaxError: Unexpected token N in JSON at position 0". I m not able to understand, exactly why the error is caught. Can somebody help me to resolve this.
const config = {
url: "https://randomuser.me/",
numberCards: 24
};
fetch(`${config.url}&amount=${config.numberCards}`)
.then(function(response) {
return response.json();
})
.then(function(apiResponse) {
// Output API response to console to view.
console.log(apiResponse);
});
It's because of this.
const config = {
url: "https://randomuser.me/",
numberCards: 24
};
fetch(`${config.url}&amount=${config.numberCards}`)
It should be,
const config = {
url: "https://randomuser.me/api/",
numberCards: 24
};
fetch(`${config.url}?amount=${config.numberCards}`)
It's because the json data are from "https://randomuser.me/api/". Not "https://randomuser.me/". And the query strings must begin with a "?" mark. "&" mark is used to separate query strings. (like this "https://example.com/?amount=24&hi=en")
I am running a node.js server running express.js on my local machine and need to decode a request made by the client, that contains a json string in it. I run the code below and get the following error.
SyntaxError: Unexpected token v in JSON at position 2
at JSON.parse (<anonymous>)
at C:\myLocation\source\repos\server\server\server.js:144:19
at Layer.handle [as handle_request] (C:\myLocation\source\repos\server\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\myLocation\source\repos\server\server\node_modules\express\lib\router\index.js:317:13)
My request is
http://localhost:1337/%7B%22Code%22:%22VNdVwY9iWhFZ114CjcDZbY%22,%22Chat%22:%22Test.txt%22%7D
The expected json is
{"Code":"VNdVwY9iWhFZ114CjcDZbY","Chat":"Test.txt"}
I get the json, but it still gives me the same error.
My code:
app.use(function (req, res) {
//console.log(req.url)
var myStr = req.url.replace('/', '')
if (myStr != false) {
let decodeStr = decodeURIComponent(myStr)
var test = JSON.parse(decodeStr)
var json = JSON.stringify(test)
if (json.includes(createkey)) {
console.log("Create: " + json)
createFile(req, res, test)
} else if (json.includes(modKey)) {
console.log("Modify: " + json)
modifyFile(req, res, test)
} else if (json.includes(readFileKey)) {
console.log("Read: " + json)
readFile(req, res, test)
}
} else {
res.sendStatus(404)
console.log("home")
}
})
Why do I get the error?
Edit 1
I added console.log(decodeStr)but I still get the error. It returns {"Code":"VNdVwY9iWhFZ114CjcDZbY","Chat":"Test.txt"}
{"Code":"'GAHGAaphgAP:gjpaGHAHAG{AaGRAP;GHPG;RA","Chat":"Test.txt"} is not a valid json, that's why you encounter that error,
The other way around, you could parse
JSON.parse('{"Code":"\'GAHGAaphgAP:gjpaGHAHAG{AaGRAP;GHPG;RA","Chat":"Test.txt"}')
Try
var uri = "http://localhost:1337/%7B%22Code%22:%22%5C'GAHGAaphgAP:gjpaGHAHAG%7BAaGRAP;GHPG;RA%22,%22Chat%22:%22Test.txt%22%7D";
I am at a dead end. I am baffled. I am passing a stringified dictionary from Python (using json.dumps()) through UDP to an Ionic 2 (Typescript) application.
The python code generating the messages:
message = { 'time' : str(round(float(op('indexFraction')[0]),3)) }
messageJSON = json.dumps(message)
#messageJSON = json.JSONEncoder().encode(message)
print(messageJSON)
op('udpout').send(messageJSON) #sending out of TouchDesigner
My callback function on the Ionic side looks like this:
socket.on('message', function (message, remoteAddress) {
if (message.length > 0) {
console.log(message, typeof(message));
// alert(message);
// process response message
var data = JSON.parse(message);
console.log(data);
if (data.time) {
alert(data.time);
}
}
});
A sample message looks like this (typeof string):
{"time": "0.934"}
// this is a string, as evidenced by the Console.log
JSON.parse() throws the following:
index.html:1 Uncaught SyntaxError: Unexpected token in JSON at position 17
I've tried all kinds of variants on the object. It passes as valid on JSONlint. It's so simple, no wacky characters. Any ideas?
Thanks,
Marc