Title: Ajax function
Last modified: August 21, 2016

---

# Ajax function

 *  [mehrwash](https://wordpress.org/support/users/mehrwash/)
 * (@mehrwash)
 * [13 years ago](https://wordpress.org/support/topic/ajax-function/)
 * I want to show the recent comments on the homepage and created a function for
   that, added the hooks and all.
    It works perfectly that is it gets me the comments,
   but when I call the same function via AJAX- for Loading on windows scroll, it
   gets messed up. The function itself output the List of comments , with gd star
   rating etc. The function does not return anything but outputs directly from the
   code using <div>s and echos.
 * I am new to all this so thank you for your help
 * My Windows Scroll Code:
 * _[ Moderator Note: [Please post code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
   or markup snippets between backticks or use the code button. ]_
 *     ```
       $(document).scroll(function(){
          // if ($(window).scrollTop() + $(window).height() == $(document).height())
       	if ($(window).scrollTop() == $(document).height() - $(window).height())  {
          		LoadonButton();
   
           }
       });
   
       function LoadonButton (){
       	jQuery.ajax({
         	url: 'http://dino-dev.com/foodie/wp-admin/admin-ajax.php',
         	data: {
         		action: 'HomeComments'
         		},
         	success: function(data, textStatus, XMLHttpRequest){  
   
         		jQuery("#post-content").append(data);
         		},
         	error: function(MLHttpRequest, textStatus, errorThrown){
         		alert(errorThrown);
        }
         });  }
       ```
   

The topic ‘Ajax function’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [mehrwash](https://wordpress.org/support/users/mehrwash/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/ajax-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
