ajax - Passing variables to jQuery from links -
i remaking page on admin section of website administer uses jquery , ajax. on 1 of pages have list of items. next each item there link this:
<a href="delete.php?id=48" class="del_link">delete</a>
if give these links class can apply jquery function of them call same function in same way. question is: best way function item's id without including javascript inline html?
update: pointers, everyone. i've ended using this:
$(".del_link").click(function(){ var del_link = $(this).attr('href'); $("#results").load(del_link, function (){ $("#results").show().delay().fadeto(2000, 0); }) })
the php file ajax calls responds in different ways if it's been requested ajax or - if it's ajax outputs response (e.g. "item deleted successfully") can displayed in #results div. if has javascript disabled client directed same php page redirect them once item removed.
quick , dirty:
$('.del_link').click(function(){ var id = $(this).attr('href').split('=')[1]; // id here });
be warned, won't work if link url has more 1 querystring parameter. in scenario you'd have more complicated parsing of attr('href')
value.
Comments
Post a Comment