self.addEventListener('sync', function(event) {
event.waitUntil(getAllData().then(function(messages) {
messages.map(function(msg) {
fetch('/storeMessage.php?user='+msg.user+'&message='+msg.message,{
method: 'GET',
headers: new Headers()
}).then(function(response) {
return response.text();
}).then(function(data) {
if (data === 'success') {
var request = self.indexedDB.open("db1",2);
request.onerror = function(event) {
alert("Why didn't you allow my web app to use IndexedDB?!");
reject('Failure!');
};
request.onsuccess = function(event) {
db = event.target.result;
db.transaction("messages","readwrite").objectStore("messages").delete(msg.id);
};
}
});
});
});//the line with error
);
});
这是我得到的错误:
Uncaught SyntaxError: missing ) after argument list
我没有经常使用异步JS。任何帮助将不胜感激