I have a href link with the text "attivo" or "non attivo" The
user can set the item to "active" or "closed" in the database using the ajax $ .post () request
I have 2 questions for them:
I cannot get a link to $ (this) to work. I tried this with a normal link and it works, but if / else is not completed ??
How can I prevent a user from clicking more than once on a link and send multiple requests? Is this a serious problem? Do I need some kind of small timer or something like that?
At first I thought of a javascript confirmation message, but it was rather annoying for this function.
HTML:
<dl id='album-list'>
<dt id="dt-2">some title</dt>
<dd id="dd-2">
some description<br />
<div class='links-right'>status: <a class='toggle-active' href='#'>non attivo</a></div>
</dd>
</dl>
<a class="test" href="#">test</a>
JS:
$('dd a.toggle-active').click(function() {
var a_ref = $(this);
var id = a_ref.parent().parent().attr('id').substring(3);
if (a_ref.text() == "non attivo") {
var new_active = "active";
$.post("ajax-aa.php", {album_id:id, album_active:new_active},
function(data) {
a_ref.text("non attivo");
});
} else {
var new_active = "closed";
$.post("ajax-aa.php", {album_id:id, album_active:new_active},
function(data) {
a_ref.text("attivo");
});
}
return false;
});
$('a.test').click(function() {
var a_ref = $(this);
$.post("ajax-aa.php", {album_id:2, album_active:"active"},
function(data) {
a_ref.text("changed");
});
return false;
})