简体   繁体   English

如何通过javascript将值传递给另一个静态页面?

[英]How to pass value to another static page via javascript?

I am trying to pass value to another page and read the value in the another page.我正在尝试将值传递给另一个页面并读取另一个页面中的值。 I use only JavaScript and jQuery.我只使用 JavaScript 和 jQuery。 Not use others language as PHP.不使用其他语言作为 PHP。 I don't want to be as like (http://www.example.com/?value=test) .我不想像(http://www.example.com/?value=test) I am trying to use POST or GET method.我正在尝试使用 POST 或 GET 方法。

On first page:在第一页:

$.post("second_page.html",{q:"test"});
window.location.replace("second_page.html");

On second page:在第二页:

var location_query = window.location.search.substring(1);
    var vars = location_query.split("&");
    for (var i in vars) {
        var param = vars[i].split("=");
        params[param[0].toString()] = param[1];
    }

If I pass value as like http://www.example.com/?q=test , the second page script is read the value, but I use this line: $.post("second.html",{q:"test"});如果我像http://www.example.com/?q=test这样传递值,则第二页脚本会读取该值,但我使用这一行: $.post("second.html",{q:"test"}); not read.不读。

How to pass value from first page to another static page via JavaScript or jQuery or ajax?如何通过 JavaScript 或 jQuery 或 ajax 将值从第一页传递到另一个静态页面?

See this post says :看到这个帖子说

POST data is data that is handled server side. POST 数据是服务器端处理的数据。 And Javascript is on client side. Javascript 在客户端。 So there is no way you can read a post data using JavaScript.因此,您无法使用 JavaScript 读取帖子数据。

but you can use cookies to read and store values:但您可以使用 cookie 来读取和存储值:

<script src="/path/to/jquery.cookie.js"></script>

you can get it from here你可以从这里得到它

Try with reading the documentation and see if this works for you.尝试阅读文档,看看这是否适合您。

在不使用GETPOST您可以使用 HTML5本地存储Web SQL传输内容

$.post and $.get send AJAX request and waiting response on current page, you cant send params for next window.location.replace by this. $.post 和 $.get 在当前页面上发送 AJAX 请求并等待响应,你window.location.replace这个发送下一个window.location.replace的参数。

Use url get-params window.location.replace("404.html?q=404");使用 url get-params window.location.replace("404.html?q=404"); and look this for get params on second page.并在第二页上查找获取参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM