jeudi 30 juin 2016

How to call ajax for a given list anchor tags with same class id but different url to call

I'm new to AJAX, and start to make an ajax able script, in which, I have a number of anchor tags with same class id. But with different url to call for each anchor tag. My function runs but, it call all the anchor tag, even i use to click on one anchor tag. But the task is done for only that clicked anchor tag And My 2nd problem is when the task completed for one anchor tag and I start to run other ones, it does not complete the task until I refresh the web page again, and click on it. But it shows that success on every anchor tag. Even the work is not done. Hope you understand my problem, Here is my ajax code.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
$('.submitdelete').click(function() {
$.ajax({
    type:'POST', 
    url: 'http://localhost/w/wp-admin/admin.php?page=rssap-feeds&action=removePosts&post=28', 
    success: function(response) {
     alert("You have made it!");
    }
});
});
</script> 
<a href="#" title="Remove Posts" class="submitdelete">Remove Posts</a>
//this is for below one
<script type="text/javascript">
 $('.submitdelete').click(function() {
$.ajax({
    type:'POST', 
    url: 'http://localhost/w/wp-admin/admin.php?page=rssap-feeds&action=removePosts&post=29', 
    success: function(response) {
     alert("You have made it!");
    }
});
});
</script>
<a href="#" title="Remove Posts" class="submitdelete">Remove Posts</a>

And if some one does not understand this problem, please comment below for more information.

Question is How do I do that correctly?

Aucun commentaire:

Enregistrer un commentaire