我能够使用Missing Manual系列JavaScript版本提供的示例非常有帮助!
OG.Q。 我看了一下尝试了几种不同的方法,但一直未能找到解决方案。
我正在尝试做什么。
的Javascript
<script>
$(document).ready(function() {
var db = openDatabase ("Test", "1.0", "Test", 65535);
$db.transaction (function (transaction)
{
var sql = "SELECT * FROM scprofiles";
transaction.executeSql (sql, undefined,
function (transaction, result)
{
//I think this is the problem host, id and name are stored in sqlite
var URL = "http://" + host + "/web/" + id + "/1/" + name + "/";
var jsonFormat = "?format=json&callback=?";
var ajaxURL = URL + jsonFormat;
$.getJSON(ajaxURL,function(data) {
$('h1').text(data.displayName);
$('#stuff').text(data.user.info);
});
}error);
});
}); //db.transaction
function ok ()
{
}
function error (transaction, err)
{
alert ("DB error : " + err.message);
return false;
}
}); // end ready
</script>
然后是html
<div class="content">
<div class="main">
<h1>JSON Data</h1>
<div id="stuff"></div>
<br class="clearLeft">
</div>
</div>
非常感谢任何建议!
布伦特 -答案 0 :(得分:0)
解决方案
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale = 1.0">
<meta charset="utf-8">
<title>Read Text</title>
<link rel="stylesheet" href="inc/jquery/j.m-1.3.2.css" />
<link rel="stylesheet" href="inc/jquery/ld.min.css" />
<script src="inc/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="inc/jquery/scdata-10.js"> </script>
<script src="inc/jquery/j.m-1.3.2.js"></script>
<script>
function saveData() {
var bnetName = document.getElementById("bnetName").value;
localStorage["bnetName"] = bnetName;
var bnetID = document.getElementById("bnetID").value;
localStorage["bnetID"] = bnetID;
var bnetRegion = document.getElementById("bnetRegion").value;
localStorage["bnetRegion"] = bnetRegion;
location.reload();
}
function loadData() {
var bnetName = localStorage["bnetName"];
var bnetID = localStorage["bnetID"];
var bnetRegion = localStorage["bnetRegion"];
if (bnetName != null) {
document.getElementById("bnetName").value = bnetName;
}
if (bnetID != null) {
document.getElementById("bnetID").value = bnetID;
}
if (bnetRegion != null) {
document.getElementById("bnetRegion").value = bnetRegion;
}
}
$(document).ready(function () // Call function when page is ready for load..
{
var URL = "http://" + localStorage.bnetRegion + "/api/sc2/profile/" + localStorage.bnetID + "/1/" + localStorage.bnetName + "/";
var jsonFormat = "?format=json&callback=?";
var ajaxURL = URL + jsonFormat;
$.getJSON(ajaxURL,function(data) {
$('#results').html( data.displayName + " " + localStorage.bnetRegion + " " + localStorage.bnetID + " <button onclick=' "+ loadData() + " '>Edit</button>" );
});
});
</script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Add StarCraft II Profile</h1>
<a href="data.html" data-shadow="false" data-iconshadow="false" data-icon="arrow-l" data-iconpos="notext" data-ajax="false">Back</a>
</div>
<div data-role="content">
<fieldset>
<span> bnet Name </span>
<input type="text" id="bnetName"><br />
<span> bnet ID </span>
<input type="text" id="bnetID"><br />
<label for="bnetRegion" class="label">Region Host</label>
<select name="bnetRegion" id="bnetRegion" data-mini="true" data-inline="true" title="Please choose region host.">
<option>--Please select one--</option>
<option value="us.battle.net">US</option>
<option value="eu.battle.net">EU</option>
<option value="kr.battle.net">KR</option>
<option value="tw.battle.net">TW</option>
<option value="www.battlenet.com.cn">CN</option>
<option value="sea.battle.net">SEA</option>
</select>
</fieldset>
<div>
<button onclick="saveData()">Save</button>
</div>
<div id="results">
</div>
</div>
</body>
</html>