我在cordova2.0.0中创建了一个应用程序,我在cordova的帮助下从java脚本调用本机函数(用c编写)。
以前我使用的是phonegap 1.0.0,其中应用程序工作正常。但是当我将它更新到cordova 2.0.0时,我收到了错误
08-07 15:24:12.527: I/Web Console(855): JSCallback Error: Request failed. at file:///android_asset/www/cordova-2.0.0.js:3698
08-07 15:22:27.815: E/Web Console(855): Uncaught TypeError: Object 0 has no method 'func' at file:///android_asset/www/file.js:359
谁能帮我解决这个问题。
我的 .html 文件的代码:
<!DOCTYPE html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="find.js"></script>
<script type="text/javascript">
function js_find(fthisval){
ws_find(socket,js_found);
}
function js_found(retval){
alert(retval);
}
function onBodyLoad(){
document.addEventListener("deviceready",onDeviceReady,false);
}
function onDeviceReady()
{
document.getElementById('d1').style.visibility = "visible";
}
</script>
</head>
<body onload="onBodyLoad()">
<div id="d1" style="visibility:hidden">
<button id="b1" onclick="js_find("ram")">Find it plz</button><br />
</div>
</body>
在 find.js 中:
var Find = function() {};
Find.prototype.func = function(funcname,funcdata) {
return cordova.exec(
null,
null,
'findPlugin',
funcname,
funcdata);
};
window.find = new Find();
function ws_find(name, param, callback){
if(undefined == callback){
var dataArray = [param, param, name];
}
else{
var dataArray = [callback, callback, name, param];
}
alert("Calling plugin function find with \r\n"+dataArray);
return window.find.func("find",dataArray);
}
该行return window.find.func("find",dataArray);
应该调用本机 java 函数,但它给了我上述错误。