我正在学习科尔多瓦 我有一个简单的项目:https://www.sitepoint.com/scanning-qr-code-cordova/ 但它似乎无法正常工作 我使用了所有代码,安装了插件:cordova插件添加phonegap-plugin-barcodescanner cordova插件添加org.apache.cordova.dialogs cordova插件添加org.apache.cordova.inappbrowser 但是当Android设备启动并且我推送"扫描"它返回一个错误,要求我在弹出消息中写一个Json响应 这是我的页面,出了什么问题?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Weather</title>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Home</h1>
</div>
<div data-role="main" class="ui-content">
<p>
<a target="_blank" href="javascript:scan();" style="text-decoration: none"><button>Scan</button></a>
<a target="_blank" href="#display" style="text-decoration: none"><button>Display Scanned Data</button></a>
</p>
</div>
</div>
<div data-role="page" id="display">
<div data-role="header">
<a target="_blank" href="#home" class="ui-btn ui-icon-home ui-btn-icon-left">Home</a>
<h1>Display</h1>
</div>
<div data-role="main" class="ui-content">
<table data-role="table" data-mode="column" id="allTable" class="ui-responsive table-stroke">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<!--<script type="text/javascript" src="script/index.js"></script>-->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script>
if(localStorage.getItem("LocalData") == null)
{
var data = [];
data = JSON.stringify(data);
localStorage.setItem("LocalData", data);
}
</script>
<script>
function scan()
{
cordova.plugins.barcodeScanner.scan(
function (result) {
if(!result.cancelled)
{
if(result.format == "QR_CODE")
{
navigator.notification.prompt("Please enter name of data", function(input){
var name = input.input1;
var value = result.text;
var data = localStorage.getItem("LocalData");
console.log(data);
data = JSON.parse(data);
data[data.length] = [name, value];
localStorage.setItem("LocalData", JSON.stringify(data));
alert("Done");
});
}
}
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
</script>
<script>
$(document).on("pagebeforeshow", "#display", function() {
$("table#allTable tbody").empty();
var data = localStorage.getItem("LocalData");
console.log(data);
data = JSON.parse(data);
var html = "";
for(var count = 0; count < data.length; count++)
{
html = html + "<tr><td>" + data[count][0] + "</td><td><a href='javascript:openURL(\"" + data[count][1] + "\")'>" + data[count][1] + "</a></td></tr>";
}
$("table#allTable tbody").append(html).closest("table#allTable").table("refresh").trigger("create");
});
function openURL(url)
{
window.open(url, '_blank', 'location=yes');
}
</script>
</body>
</html>
&#13;