LogCat显示cordova.js第415行(功能如下所示的checkArgs)引发Uncaught TypeError导致我的应用程序中断。

日志显示Uncaught TypeError: Wrong type for parameter "successCallback" of Device.getInfo: Expected Function, but got Undefined.

仅在进行AJAX呼叫时发生错误...我的AJAX呼叫在下方

function checkArgs(spec, functionName, args, opt_callee) {
    if (!moduleExports.enableChecks) {
        return;
    }
    var errMsg = null;
    var typeName;
    for (var i = 0; i < spec.length; ++i) {
        var c = spec.charAt(i),
            cUpper = c.toUpperCase(),
            arg = args[i];
        // Asterix means allow anything.
        if (c == '*') {
            continue;
        }
        typeName = utils.typeName(arg);
        if ((arg === null || arg === undefined) && c == cUpper) {
            continue;
        }
        if (typeName != typeMap[cUpper]) {
            errMsg = 'Expected ' + typeMap[cUpper];
            break;
        }
    }
    if (errMsg) {
        errMsg += ', but got ' + typeName + '.';
        errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
        // Don't log when running unit tests.
        if (typeof jasmine == 'undefined') {
            console.error(errMsg);
        }
        throw TypeError(errMsg);
    }
}


我的AJAX电话:

var ajax = $.ajax({

    type: "POST",
    url: "http://www.example.com/tools/api/index.php",
    data: api,
    dataType:"json",
    async:async

});


ajax.done(function( response ) {

// do this

});

ajax.fail(function( jqXHR, textStatus, errorThrown ) {

// do that

});


注意:我正在使用build.phonegap.com并使用版本3.3.0

任何想法或建议,将不胜感激。

更新:遍历所有使用功能checkArgs的源代码,我发现了这一点。这是唯一使用checkArgs的其他函数

/**
 * Get device info
 *
 * @param {Function} successCallback The function to call when the heading data is available
 * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
 */
Device.prototype.getInfo = function(successCallback, errorCallback) {
    argscheck.checkArgs('fF', 'Device.getInfo', arguments);
    exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
};


为什么会引发错误...我不确定

最佳答案

原来问题出在拉window.device数据上。

我尝试一次记录所有设备api.device = window.device ...原来设备是cordova函数,而不是附加了静态值的对象。

我不得不将代码更改为

api.device = {};
api.device.name = device.name;
api.device.phonegap = device.phonegap;
api.device.platform = device.platform;
api.device.uuid = device.uuid;
api.device.version = device.version;


我刚去过哪里

api.device = device;


希望这可以在将来对其他人有所帮助。

09-10 11:18
查看更多