Unexpected token } but only in older versions of webview, not newer ones

ぐ巨炮叔叔 提交于 2021-02-08 12:13:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!