开发者

Changing a url depending on what link chosen (HTML) no asp

TLDR I need to change a javascript variable on the same page after clicking a link (can be from a different page) so that the getjson request pulls different data without having to duplicate on html pages.


I am using some getJSON requests with Jquery, to make calls to populate my pages. I want to be able to (in plain HTML / javascript) when the user开发者_如何学C clicks say "link 1" or "link 2" to open the same page (say page.html) but change the get request url to "link 1" or "link 2".

Page.html

var url = ??;    
$.getJSON(url, function(data){}

link 1

var url = host/link1
<a href="page.html">link1</a>

link2

var url = host/link2
<a href="page.html">link2</a>

So I call the same page but am able to populate it with different content. Purposely staying away from asp. Was thinking maybe of inserting the content into a div after page load so the url can be set or something along those lines.

Edit1 I also need to redo the getjson request after "page.html" loads and re run it every second. I have done this with other pages but not in the case where I need to pull on data depending on a link that is automatically generated.

Edit2 Decided to go with the Cookie approach using jquery and jquery cookie as it seemed most reasonable. See thread here

Any ideas how I might go about this?


$('a[href=page.html]').click(function()
{
  $.getJSON('host/' + $(this).text(), function(data){});
  return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜