i made a php script that handle URL and give back Title, FirstImage and Description of a given url.
In my website, all links i want to replace with previews has “replaced_link” class.
I suppose this function should work, but it does not:
var $alinks = $('a.replaced_link');
$alinks.each(function(){
$this=$(this);
url = $this.attr('href');
$.ajax({
type:"GET",
url:"data.php?getlink="+url,
beforeSend: function(){
$this.append('<img align=center src="images/loader_dark.gif">');
},
success: function(data){
if (data) {
$this.after(data);
$this.remove();
}
},
error: function(){
$this.find('img').remove();
}
});
});
On a single link, it’s working right. If there is more than one “a.replaced_link”, all the previous remains with spin loading and only the last take the first link (!!!).
If i remove “$this.remove()”, all links will be appended in the last a.replaced_link!
I hope to be clear….
It seems that $this are not splitted as differents objects on “.each”
How to solve?
P.s. I want to remove object because it’s possible that i need to trigger this function more than one time… and i don’t want to reload each URL
Implicit global in the house! Say
instead of
Same with url obv.