如何通过javascript价值传递到另一个静态页面? [英] How to pass value to another static page via javascript?

查看:105
本文介绍了如何通过javascript价值传递到另一个静态页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传递值到另一个页面,并读取另一页的价值。我只用javascript和jQuery的。不得使用其他语言PHP。我并不想成为像(http://www.example.com/?value=test)。我想使用POST或GET方法。

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.

在第一页:

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

在第二页:

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];
    }

如果我传递价值,如 http://www.example.com/?q=test ,第二页脚本读取的值,但我用这个行: $后(second.html,{问:测试}); 不读

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

如何从第一页通过JavaScript或jQuery的AJAX或价值传递到另一个静态页面?

How to pass value from first page to another static page via javascript or jquery or ajax?

推荐答案

$。员额和$不用彷徨发送AJAX请求,并在当前页面等待响应,你不能送PARAMS明年 window.location的。替换此。

$.post and $.get send AJAX request and waiting response on current page, you cant send params for next window.location.replace by this.

使用URL获得-PARAMS window.location.replace(?404.html Q = 404); ,并查找的这个对第二页GET参数。

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

这篇关于如何通过javascript价值传递到另一个静态页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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