可以获取<a> tags include data?

时间:2018-12-11 18:52:50

标签: javascript jquery html

I know that requests placed by jQuery $.get() can include an optional parameter for additional data. I was wondering if there was any way to pass that information through requests that come about by clicking an link, or relocation the windows location.

2 个答案:

答案 0 :(得分:2)

是的,您可以使用Query String

节选:

  

包含查询字符串的典型URL如下:

     

http://example.com/over/there?name=ferret

     

当服务器收到对此类页面的请求时,它可以运行程序,将查询字符串(在这种情况下,name = ferret不变)传递给程序。问号用作分隔符,不是查询字符串的一部分。

所以您的锚点可能是:

<a href="http://example.com/over/there?name=ferret">My Link</a>

<a href="//example.com/over/there?name=ferret">My Link</a>

<a href="/there?name=ferret">My Link</a>

请注意,您可以获得caching issues by links/get requests

答案 1 :(得分:0)

访问页面时,通过链接传递数据的唯一方法是使用URL Parameters/Query Strings