-3

Possible Duplicate:
using jquery $.ajax to call a PHP function

I have a couple of links (all different) that I want to execute without linking anywhere. Unlike other questions I don't want to send any data using a form, nor do I want to like to the same page everytime the link is clicked, I simply want to run the php script associated with the link but stay on the page the user is currently on. Ajax? jQuery?

Community
  • 1
  • 1
user1763879
  • 7
  • 1
  • 6

1 Answers1

3
<a class="ajaxLink" href="myScript.php">Ajaxed link</a>

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

$('.ajaxLink').click(function(e){
  e.preventDefault(); // Prevents default link action
  $.ajax({
     url: $(this).attr('href'),
     success: function(data){
       // Do something
     }
  });
});

The default method for jQuery ajax is GET, but you can change this. Read about the options available at the above link.

ahren
  • 16,803
  • 5
  • 50
  • 70
  • thanks, but there will be several links on one page, so wouldn't using class cause 'confusion' between the links? – user1763879 Nov 27 '12 at 21:45
  • 1
    It would separate your ajax'd links from your normal links... The result of which is clarity, not confusion... – ahren Nov 27 '12 at 21:46