Add url with jquery session id

I have a static session id that I am using and you need to add it to the url when clicked, but it doesn't seem to be right. If you go to http://www.mysite.com/test.php , you get a redirect, you need to add the XYX session ID, so the correct URL to get to the page will be http://www.mysite.com/ test.php? sessionid = XYX

<a href="http://www.mysite.com/test.php" class="foo">link here</a>

$('.foo').click(function(){
  (this).append(?sessionid=XYX');'
});

I know this is wrong, all the documentation I found is much more complicated than my needs. thank!

+3
source share
4 answers

URL-, e.preventDefault, , id URL- :

<a href="http://www.mysite.com/test.php" class="foo">link here</a>

$('.foo').click(function(e)
{
    e.preventDefault();
    window.location = $(this).attr('href') + '?sessionid=XYX';
});
+5

href, :

$('.foo').click(function(){
  $(this).attr('href', $(this).attr('href') + '?sessionid=XYX');
});

- , URL- , . , , . : http://jsfiddle.net/Mgv34/

+1

.

$('.foo').click(function(){
  if( !this.search ) this.search = '?sessionid=XYX';
});

search .

0

hrefs onClick , , href '? sessionid = XYX', http://www.example.com/test.php?sessionid=XYX?sessionid=XYX "

$('.foo').click(function(){
  var lHref = $(this).attr('href');
  var lStr = '?sessionid=XYX';
  if (lHref.indexOf(lStr) < 0) { 
    $(this).attr('href', lHref + lStr);
  }
});
0

Source: https://habr.com/ru/post/1787714/


All Articles