-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?

4

1 回答 1

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
     }
  });
});

jQuery ajax 的默认方法是 GET,但您可以更改它。阅读上述链接中可用的选项。

于 2012-11-27T21:42:34.240 回答