0
我正在測試一個更大的解決方案的簡單腳本;我從外部JSON文件中檢索信息並在PhoneGap應用程序中顯示它。該腳本根據需要工作,除了當我更改外部JSON文件的內容(而不是結構)時。事實上,我甚至可以從服務器中刪除JSON文件,而腳本仍然顯示原始的JSON內容。顯然有東西在某處緩存。有沒有辦法禁用這樣的?Phonegap緩存JSON?
順便說一句我在本地設備上通過USB調試而不是仿真器來運行它。
這裏是代碼(控制檯日誌通過瀏覽器是目前對早期調試):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<script>
$(document).ready(function() {
console.log("ready!");
});
$.getJSON("http://www.serverxyz.com/test.json", function(data) {
var items = [];
$.each(data, function(key, val) {
items.push("<li id='" + key + "'>" + val + "</li>");
});
$("<ul/>", {
"class": "my-new-list",
html: items.join("")
}).appendTo("body");
});
</script>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
這裏是JSON內容:
{
"Goal One": "Activity One Completed",
"Goal Two": "Activity Two Completed",
"Goal Three": "Activity Three Completed",
}