隐藏 URL 参数并读取它们 [英] Hide URL parameters and read them

查看:65
本文介绍了隐藏 URL 参数并读取它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么方法可以隐藏URL参数,然后用代码读取隐藏的参数?例如,我的页面中有这个:example.com/transaction.html?price=10".

Is there any method to hide URL parameters and then read the hidden parameters with code? For example I have this in my page: "example.com/transaction.html?price=10".

我尝试使用 Base64 进行编码,但它没有按预期工作(编码有效,解码无效),所以我想隐藏 price=10 或 transaction.html?price=10.

I have tried to encode with Base64, but it doesn't work as expected (encoding works, decoding not), so I want to hide either the price=10 or transaction.html?price=10.

我听说 AngularJS 可以隐藏参数,但它可以读取隐藏"的参数或者它是如何工作的?

I heard that AngularJS could hide parameters, but can it read "hidden" parameters or how does it work?

提前致谢!

function getUrlVar() {
    var result = {};
    var location = window.location.href.split('#');
    var parts = location[0].replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m,key,value) {
        result [key] = value;
    });
    return result;
}

推荐答案

如果不想在地址栏中向用户展示查询参数,可以使用Javascript或者jquery轻松实现也需要切换到角度只是为了这个.

If you don't want to show the query parameters to the users in the address bar, you can easily achieve it using Javascript or jquery also need to switch to angular just for this.

你可以做的是代替使用 </a> 获取该查询的数据,该查询会将用户重定向到链接说 www.something.com?price=10 而不是您可以做的就是使用一个按钮

What you can do is instead of using <a href = ....> </a> to fetch the data for that query which will redirect the user to the link say www.something.com?price=10 instead of this what you can do is use a button as

<button type="button" onclick="fetch()">获取数据</button>

并且在您的 Javascript 文件中,您可以通过这种方式发出 GET 或 POST 请求,这些您想要隐藏的参数将不会显示,只是这些将在后台发送到服务器,而无需更改您的地址.

and in your Javascript file you can make a GET or POST request in this way these parameters you want to hide won't be shown, it's just these will be send to the server in background without changing your address.

为了制作这个 GET 请求,你可以做一些事情,比如假设你从文本字段发送数据:

To make this GET Request you can do something like assuming you are sending the data from a text field :

$("#button").click(function() {
      $.ajax({
          type: "POST",
          url: "www.something.com/",
          data: {
            price: $("#price")
          },
          success: function(data) {
            // do something with the data you received}
          });
      })

<input type=text id="price" />
<button id="button">Send</button>

现在您在后台获取数据,而无需在地址栏中向用户显示参数.

Now you got the data in background without showing the parameters to the user in their address bar.

这篇关于隐藏 URL 参数并读取它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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