Javascript 检索文本输入';存储到localStorage中的s值
我正在尝试从url解析JSON数据(仅从JSON提供数据)并将值存储在localstorage中现在我正在尝试从一个文件检索存储在localstorage中的值到另一个文件,存储的值位于数组对象的from中。检索时,我只获取其他文件中的最终对象。有人能帮我检索所有的对象吗?我在new.html(这里我试图将数据存储在localstorage)和new1.html(这里我正在检索数据)下面附加代码。多谢各位 new.html:Javascript 检索文本输入';存储到localStorage中的s值,javascript,jquery,local-storage,Javascript,Jquery,Local Storage,我正在尝试从url解析JSON数据(仅从JSON提供数据)并将值存储在localstorage中现在我正在尝试从一个文件检索存储在localstorage中的值到另一个文件,存储的值位于数组对象的from中。检索时,我只获取其他文件中的最终对象。有人能帮我检索所有的对象吗?我在new.html(这里我试图将数据存储在localstorage)和new1.html(这里我正在检索数据)下面附加代码。多谢各位 new.html: <html> <head> <m
<html>
<head>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width ,height=device-height"/>
</head>
<body>
<div id="header">
<h1> Login </h1>
</div>
<div id="section">
<!--script type="text/javascript"
charset="utf-8" src="cordova-1.7.0.js"></script-->
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$("#submit").click(insertId);
});
function insertId() {
// Getting the value of your text input
var did = document.getElementById("deviceId").value;
if (did == null || did == "") {
alert("Kindly enter a valid Device ID");
return false;
} else {
console.log("id: ", did);
}
window.alert("DID entered is : " + did);
window.open("new1.html");
$.ajax({
url : "https://api.thingspeak.com/channels/9/feeds.json?results=10",
dataType:"json",
cache: false,
error:function (xhr, ajaxOptions, thrownError){
debugger;
alert(xhr.statusText);
alert(thrownError);
},
success : function(json1) {
console.log(json1);
json1.feeds.forEach(function(feed, i) {
console.log("\n The deails of " + i + "th Object are : \nCreated_at: " + feed.created_at + "\nEntry_id:" + feed.entry_id + "\nField1:" + feed.field1 + "\nField2:" + feed.field2);
localStorage.setItem('Created_at', feed.created_at);
var create = localStorage.getItem('Created_at');
console.log(create);
localStorage.setItem('Entry_id', feed.entry_id);
var entry = localStorage.getItem('Entry_id');
console.log(entry);
localStorage.setItem('Field1', feed.field1);
var fd1 = localStorage.getItem('Field1');
console.log(fd1);
localStorage.setItem('Field2', feed.field2);
var fd2 = localStorage.getItem('Field2');
console.log(fd2);
});
}
});
return false;
}
</script>
<form id="insertId">
<br><input type="text" placeholder="DeviceId" id="deviceId" /><br>
<br>
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
</div>
</body>
登录
$(文档).ready(函数(){
$(“#提交”)。单击(插入);
});
函数insertId(){
//获取文本输入的值
var did=document.getElementById(“deviceId”).value;
if(did==null | | did==“”){
警报(“请输入有效的设备ID”);
返回false;
}否则{
日志(“id:,did”);
}
window.alert(“输入的DID为:+DID”);
window.open(“new1.html”);
$.ajax({
url:“https://api.thingspeak.com/channels/9/feeds.json?results=10",
数据类型:“json”,
cache:false,
错误:函数(xhr、ajaxOptions、thrownError){
调试器;
警报(xhr.statusText);
警报(thrownError);
},
成功:函数(json1){
console.log(json1);
forEach(函数(feed,i){
console.log(“\n”+i+”对象的结尾是:\n创建位置:“+feed.created”\u位置+”\n条目id:“+feed.entry\u id+”\nField1:“+feed.field1+”\nField2:“+feed.field2”);
localStorage.setItem('Created_at',feed.Created_at');
var create=localStorage.getItem('Created_at');
console.log(创建);
localStorage.setItem('Entry\u id',feed.Entry\u id);
var entry=localStorage.getItem('entry_id');
控制台日志(条目);
localStorage.setItem('Field1',feed.Field1);
var fd1=localStorage.getItem('Field1');
控制台日志(fd1);
localStorage.setItem('Field2',feed.Field2);
var fd2=localStorage.getItem('Field2');
控制台日志(fd2);
});
}
});
返回false;
}
new1.html:
<html>
<body onload="init();">
<div id="header">
<h1> USER DETAILS </h1>
</div>
<div id="section">
<script>
// Called on body's `onload` event
function init() {
// Retrieving the text input's value which was stored into localStorage
var create = localStorage.getItem('Created_at');
console.log(create);
document.writeln("<br>Created_at = "+create);
var entry = localStorage.getItem('Entry_id');
document.writeln("<br>Entry_id = "+entry);
var fd1 = localStorage.getItem('Field1');
document.writeln("<br>Field1 = "+fd1);
var fd2 = localStorage.getItem('Field2');
document.writeln("<br>Field3 = "+fd2);
}
</script>
<body onload="init();">
</body>
</div>
</body>
用户详细信息
//在body的“onload”事件中调用
函数init(){
//检索存储在localStorage中的文本输入值
var create=localStorage.getItem('Created_at');
console.log(创建);
document.writeln(“
Created_at=“+create”);
var entry=localStorage.getItem('entry_id');
document.writeln(“
Entry\u id=“+Entry”);
var fd1=localStorage.getItem('Field1');
document.writeln(“
Field1=“+fd1”);
var fd2=localStorage.getItem('Field2');
document.writeln(“
Field3=“+fd2”);
}
如果您真的将所有数据都存储在浏览器本地存储中,您是否签入了浏览器本地存储?您的json(feeds.json)中只有一条记录是的。我已将签入的所有数据存储在浏览器本地存储中consolelog@pryxenNo.I在json(feeds.json)中有10条记录,您可以查看url@NitinDhomse