views:

193

answers:

1

hello, I have a button that depending on a class value should send different values to the POST however what ever happens it is only running one condition, whatever I do I can only get it to send the POST the method=add data.

This is my code

$("a.navlink").click(function (ev) {
    $(this).removeClass("active");
    var url = $(this).attr("href")
    ev.preventDefault();
    if($('a.navlink:not(.active)')) {

        $.ajax ({
             url: url,
             type: "POST",
             data: "method=add",
             success : function (html) {
                $('#accordion').accordion('destroy');
                 $("#accordion").append(html);
                 $('#accordion').accordion({
                     active: 0,
                     header:'h2.Blog'
                 });
             //alert(accordion())
             }
         });
    }
    if ($(this).hasClass("active")) {
    //  $(this).addClass('active')
    $.ajax ({
         url: url,
         type: "POST",
         data: "method=delete",
         success : function (html) {
            alert("hello")
            $(this).removeClass('active')
         //alert(accordion())
         }
     });    
    }


     });

Basically what I need is, if when the button is clicked it gets a class called active added to it and the ajax runs, when it is clicked again, the class needs to be removed and the ajax run, is this possible?

+5  A: 
Tatu Ulmanen
Essentially one the user clicks the link the first time it needs to have the class active added to it and the Ajax that passes the method=call to the POST, when the user clicks it again it needs to remove the class active and run the ajax that send the method=delete to POST
sico87
I edited my answer to do just what you described.
Tatu Ulmanen