SyntaxError:missing; before语句在jquery中获取此错误

时间:2014-03-12 07:00:43

标签: javascript jquery cordova

    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 +&#34 ;;");我得到" SyntaxError:missing;在陈述之前#34;这个错误。这是一个用于解压缩zip文件的phonegap插件。请让我知道我错在哪里。

2 个答案:

答案 0 :(得分:0)

尝试使用:

eval("var v="+r);

或只是:

var v = r;

答案 1 :(得分:-1)

通常当你说错误时;缺少,您必须先查看该行(有时是之前加载的文件)。

在你的情况下:

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

你错过了;在行console.log(r)

的末尾