jquery fadein effect not working onclick

I am having issues getting a fadeIn to work with my jquery. Was hoping someone could help. Basically, I have a button that I click on my page that will essentially pull in the next set of results (code below). I'd like to add the fadein effect when the results are returned to the screen, however I am doing something wrong. Below are examples I tried, but are not working.

example 1

var number = 0;
$(function(){
  $('#showMore').click(function(event) {
     event.preventDefault();
    number++;

    $.ajax({
       type: "POST",
       url: "/getnext.php",
       data: {"count":number},

       success: function(results){
        $('#results').html(results);
        $('#results').fadeIn()


       }
     });

  });

});

example 2

var number = 0;
$(function(){
  $('#showMore').click(function(event) {
     event.preventDefault();
    number++;

    $.ajax({
       type: "POST",
       url: "/getnext.php",
       data: {"count":number},

       success: function(results){
        $('#results').fadeIn().html(results);


       }
     });

  });

});

Any thoughts on why this is not working?

Answers


Make sure there is an response first :

$('#results').html(results).hide().fadeIn();

Need Your Help

Status of Phantomjs onResourceReceived Response Body Work

javascript ajax project phantomjs httpresponse

I recently discovered that I cannot read the response body of an ajax request with PhantomJS. Looking into this issue, it appears this has been kicked around for quite some time with no complete

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.