问题
I'm getting Uncaught SyntaxError: Unexpected token }
in this code on Android 4.4's webview, but same code is working on Android 5.0 or higher.
What makes this fail on older webview versions?
function isyeriekle(satkir) {
var ilanbasligi = $("input[name='ilanbasligi']").val();
var ilanfiyati = $("input[name='ilanfiyati']").val();
var mkare = $("input[name='mkare']").val();
var binayasi = $("input[name='binayasi']").val();
var klnmdrm = $("input[name='durumu']").val();
var ilannotlari = $("#ilannotlari").val();
var ilanfotolari = $('#list').html();
if ($.trim(ilanbasligi) == '' || $.trim(ilanfiyati) == '' || $.trim(mkare) == '' || $.trim(klnmdrm) == '' || $.trim(ilannotlari) == '' || $.trim(binayasi) == '') {
myApp.alert('Bir veya daha fazla kutucuk boş görünüyor...');
}
else {
myApp.showPreloader('İlan kaydediliyor...');
$.post(sunucuurl + "/iilankayit.php", {
ilanbas: ilanbasligi,
ilanfiyat: ilanfiyati,
mkare: mkare,
kullanimdurumu: klnmdrm,
ilannotlari: ilannotlari,
satkira: satkir,
gilanfotolar: ilanfotolari,
binayasi
}, function(data, status) {
if (data == 'verilereklendi') {
myApp.hidePreloader();
myApp.alert('İlan kaydedildi!');
setTimeout(function() {
window.location.href = 'anasayfa.html';
}, 2000);
}
else {
myApp.hidePreloader();
myApp.alert('İlan kaydedilemedi... ' + data);
}
});
}
}
回答1:
The problem is on the last line of the object initializer:
satkira: satkir,
gilanfotolar: ilanfotolari,
binayasi // <=====
}, function(data, status) {
if(data == 'verilereklendi') {
That's using an ES2015+ (aka "ES6+") syntax feature which presumably isn't available in the environment where it isn't working. The ES5 equivalent is to add the : value
part:
satkira: satkir,
gilanfotolar: ilanfotolari,
binayasi: binayasi // <=====
}, function(data, status) {
if(data == 'verilereklendi') {
来源:https://stackoverflow.com/questions/43188280/unexpected-token-but-only-in-older-versions-of-webview-not-newer-ones