![](/img/trans.png)
[英]uncaught reference error: FileTransfer not defined at cordova.js(3.0.0)
[英]cordova.js is throwing Uncaught TypeError with an ajax call
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;
希望這可以在將來對其他人有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.