Ajax doesn't work sometimes

ajax, jquery

Solution

Try this. Probably you have elements added to page after listener is set.

$(document).ready(function(){
 $(document).on('click', '.AlarmLink', function() {
   alert('ok');
            $(".page-content").empty();
            $("#alarm-loader").css('display','block');
            $.post($(this).attr("href"),                       
                       function(data){
                        var PageContent = $(data).find(".page-content");
                        $("#alarm-loader").css('display','none');
                        $(".page-content").append(PageContent.html());
                    });
            return false;
  })
});

Problem

I'm using Ajax in my web application, and here's my Ajax Jquery function : ``` $(".AlarmLink").click(function(){ alert('ok'); $(".page-content").empty(); $("#alarm-loader").css('display','block'); $.post($(this).attr("href"), function(data){ var PageContent = $(data).find(".page-content"); $("#alarm-loader").css('display','none'); $(".page-content").append(PageContent.html()); }); return false; }); ``` and I call it from HTML link using the class="AlarmLink". But the problem is that this works sometimes and sometimes not .

Original source