0

In a PHP Project I have hyperlink :

<a href="addid.php?id='. $Id . '">| Name |</a>';

When a user click on the link I need to add the selected "id" to session

addid.php Code :

session_start();
$_SESSION['id'] = $_GET['id'];

I need to accomplish this without reloading the page (need to add the "id" to session in background).

How to call addid.php with Javascript & jQuery?

NOTE: I tried this code, but it does load the addid.php in browser

$('a').click(function(){
      $.ajax(); 
        return false; 
});
1
  • Not sure if that is really your best option... Commented Feb 20, 2012 at 17:37

3 Answers 3

2
$('a').click(function(){
   $.get($(this).attr('href'));
   return false;
});
Sign up to request clarification or add additional context in comments.

Comments

1

Give your link an id:

<a id="something" href="addid.php?id='. $Id . '">| Name |</a>';

and then you can easily refer to it:

$('a#something').click(function(e) {
    e.preventDefault();
    $.get($(this).attr('href')); // no handler fire and forget
});

The code you tried is invalid - have a look at the api for the jquery function you're using. url is a mandatory argument.

Check using developer tools/firebug/whatever you have installed that the request is sent to the right place, and the response if what you expect.

Comments

0

Look at jquery:

http://api.jquery.com/jQuery.get/

Use ajax and set the id as a parameter in the data string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.