简体   繁体   中英

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. Not use others language as PHP. I don't want to be as like (http://www.example.com/?value=test) . I am trying to use POST or GET method.

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"}); not read.

How to pass value from first page to another static page via JavaScript or jQuery or ajax?

See this post says :

POST data is data that is handled server side. And Javascript is on client side. So there is no way you can read a post data using JavaScript.

but you can use cookies to read and store values:

<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.

Use url get-params window.location.replace("404.html?q=404"); and look this for get params on second page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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