What I would like to do is to take several links that may be on a page and send only the link that was clicked on to a PHP script to be parsed.
<a href="?something=2&id=100&somethingelse=55" class="link">My First Link</a>
<a href="?something=3&id=400&somethingelse=65" class="link">My Second Link</a>
What I would like is to grab the link and have it passed to PHP. Using this code, I am only ever able to get the first link, no matter which link I click on.
I’d rather have one function to send these links into than a function for each and every hyperlink I have in the site. I’m simply trying to condense or consolidate the amount of functions needed that basically do the same thing.
Here is what I have so far:
$(".link").click(function() {
var v1 = $("a.link").attr("href");
// var v1 = $("a.ajax-link")[2].href;
var dataString = 'v1='+ v1;
$.ajax({
type: "POST",
url: "/",
data: dataString,
dataType: 'json',
success: function(data) {
if(data.success == 1){
alert(data.success);
}
else{
alert(data.success);
}
}
});
return false;
});
Change your code to get the event target (
thisin this case):