如何将本地存储输出到服务器? [英] How do I get the local storage output into the server?

查看:102
本文介绍了如何将本地存储输出到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本的目标是在远程位置使用iPad时,如果信号不允许连接到服务器,则将表单输出保存到浏览器中的本地存储。然后在信号恢复后随后获取数据。

我已经花了几周的时间尝试让本地存储以php格式反馈到我的页面。我把它作为一个javascript回来了,但我无法弄清楚如何发送到服务器,然后将其返回到页面。我从网站上复制了一些不同的脚本,包括ajax,但是我真的不懂javascript来使它工作。 javascript都不是我自己的创作。可以下载并运行该脚本以显示脚本是否正常工作。

我最初提供的代码已被某人更改。它现在根本不起作用,因为脚本标签已被删除。



更新:我现在已将代码示例更改回原始版本,而不是建议为POST更改GET。



我尝试了什么:



<?php 
$ php_result = $ _ POST ['result'];
print这是来自服务器的php结果< br> result =。$ php_result。< br>< br>;
print这是存储的javascript输出......;
$ customer = $ _ POST ['customer'];

?>
<!DOCTYPE html>
< html>
< body>
< div id =result>< / div>
< form method =POSTaction =name =cust_form>
< p>在框中输入任何内容< / p>
< input type =textname =customersize =10value =<?php print $ customer;?>>

< p>< input type =submitvalue =Continue>< / p>
< / form>
< script>
var customer =<?php echo json_encode($ customer); ?取代;
if(typeof(Storage)!==undefined){
localStorage.setItem(cust,customer);

document.getElementById(result)。innerHTML = localStorage.getItem(cust);

xhttp.onreadystatechange = function(){
getElementById(result)。innerHTML = localStorage.getItem(cust);

if(this.readyState == 4&& this.status == 200){

}
};


xhttpRequest.open('POST','http://www.jhw1.com/local_store.php',true);
xhttpRequest.send();
};


< / script>
< / body>
将/ HTML>

解决方案
php_result =

_POST [结果];
print这是来自服务器的php结果< br> result =。


php_result。< br>< br>;
print这是存储的javascript输出......;


The object of my script is to save form output to local storage in the browser if the signal does not allow connection to server, using an iPad in remote locations. Then subsequently getting the data back when the signal is restored.
I have been a couple of weeks trying to get the local storage to feed back onto my page in php format. I get it back OK as a javascript but I cannot work out how to send to the server and then get it back to the page. I have copied a few different bits of script from websites, including ajax, but I really do not understand javascript enough to make it work. None of the javascript is my own creation. The script can be downloaded and run to show the script working.
The code I originally gave has been changed by someone. It will not work at all now because the script tags have been removed.

UPDATE: I have now changed the code sample back to original with the changes suggested for POST instead of GET.

What I have tried:

<?php
$php_result=$_POST['result'];
print "This is the php result from server <br>result=".$php_result."<br><br>";
print "This is the javascript output from storage...";
$customer=$_POST['customer'];

?>
<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<form method = "POST" action = "" name="cust_form">
<p>Type anything in the box</p>
<input type="text" name="customer" size="10" value="<?php print $customer;?>">

<p><input type="submit" value="Continue"></p>
</form>
<script>
var customer = <?php echo json_encode($customer); ?>;
if (typeof(Storage) !== "undefined") {
localStorage.setItem("cust", customer);

document.getElementById("result").innerHTML = localStorage.getItem("cust");

xhttp.onreadystatechange = function() {
getElementById("result").innerHTML = localStorage.getItem("cust");

  if (this.readyState == 4 && this.status == 200) {

  }
};


xhttpRequest.open('POST', 'http://www.jhw1.com/local_store.php', true);
xhttpRequest.send();
};


</script>
</body>
</html>

解决方案

php_result=


_POST['result']; print "This is the php result from server <br>result=".


php_result."<br><br>"; print "This is the javascript output from storage...";


这篇关于如何将本地存储输出到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆