簡體   English   中英

語法錯誤:缺少; before 語句在 jquery 中出現此錯誤

[英]SyntaxError: missing ; before statement getting this error in jquery

    PhoneGap.exec = function(success, fail, service, action, args) {
        try {
            var callbackId = service + PhoneGap.callbackId++;
            if (success || fail) {
                PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
            }

            var r = prompt(JSON.stringify(args), "gap:"+JSON.stringify([service, action, callbackId, true]));
            console.log(r)
            // If a result was returned
            if (r.length > 0) {
                eval("var v="+r+";");

                // If status is OK, then return value back to caller
                if (v.status === PhoneGap.callbackStatus.OK) {

                    // If there is a success callback, then call it now with
                    // returned value
                    if (success) {
                        try {
                            success(v.message);
                        } catch (e) {
                            console.log("Error in success callback: " + callbackId  + " = " + e);
                        }

                        // Clear callback if not expecting any more results
                        if (!v.keepCallback) {
                            delete PhoneGap.callbacks[callbackId];
                        }
                    }
                    return v.message;
                }

                // If no result
                else if (v.status === PhoneGap.callbackStatus.NO_RESULT) {

                    // Clear callback if not expecting any more results
                    if (!v.keepCallback) {
                        delete PhoneGap.callbacks[callbackId];
                    }
                }

                // If error, then display error
                else {
                    console.log("Error: Status="+v.status+" Message="+v.message);

                    // If there is a fail callback, then call it now with returned value
                    if (fail) {
                        try {
                            fail(v.message);
                        }
                        catch (e1) {
                            console.log("Error in error callback: "+callbackId+" = "+e1);
                        }

                        // Clear callback if not expecting any more results
                        if (!v.keepCallback) {
                            delete PhoneGap.callbacks[callbackId];
                        }
                    }
                    return null;
                }
            }
        } catch (e2) {
            console.log(e2);
        }
    };

我正在使用這個函數並在 eval("var v="+r+";"); 我收到“SyntaxError: missing ; before statement”這個錯誤。 這是一個用於提取 zip 文件的 phonegap 插件。 請讓我知道我錯在哪里。

嘗試使用:

eval("var v="+r);

要不就:

var v = r;

通常當您說錯誤時; 丟失,您必須查看之前的行(或者有時是之前加載的文件)。

在你的情況下:

console.log(r)
// If a result was returned
if (r.length > 0) {
    eval("var v="+r+";");

你錯過了一個 ; console.log(r)行的末尾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM