How to add newest DIVs at the top of the page

I started to create a service to attempt to replicate the same functionality of Facebook posts and that is to have the newest comments on top.  My concern is that the newest posts to the page are being listed on the bottom.  How do I reverse that and add the newest posts to the top?  Thanks!

Here is what I have so far.  In the service page, here is what I have:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;

namespace NorthWindInfiniteScroll
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Test" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Test.svc or Test.svc.cs at the Solution Explorer and start debugging.
    [ServiceContract]
    public class Test
    {
        [OperationContract]
        [WebInvoke(Method= "POST",
            BodyStyle=WebMessageBodyStyle.Wrapped,
            ResponseFormat= WebMessageFormat.Json)]
        public string MyFunction(string Count)
        {
            

            return "The Count you passed in is: " + Count.ToString() + " " + DateControl().ToString() +  Control();
        }

        public DateTime DateControl()
        {

            DateTime datetime;

            datetime = DateTime.Now;

            return datetime;
        }

        public string Control()
        {
            string hello;

            LiteralControl literalcontrol = new LiteralControl();

            ImageButton imagebutton = new ImageButton();

            literalcontrol.Text = "<div><h1><b>hello world</b></h1></div>" + "<img id='Image1' src='Images/loading.gif'/>";
            

            hello = literalcontrol.Text;

            return hello;
        }
    }
}

Open in new window


And in the web page calling the service page, this is what I have:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallWCF.aspx.cs" Inherits="NorthWindInfiniteScroll.CallWCF" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Call WCF</title>
    <script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
    <script type="text/javascript">

        var counter = 0;
        function CallMyService() {

            counter++;

            $.ajax({
                type: "POST",
                url: "Test.svc/MyFunction",
                data: '{"Count": "' + counter + '"}',
                contentType: "application/json",
                success: ServiceSucceeded,
                error: ServiceFailed
            });
        }

        function ServiceFailed(result) {

            Log('Service call failed: ' + result.status + ' ' + result.statusText);
        }

        function ServiceSucceeded(result)
        {
            resultObject = result.MyFunctionResult;
            Log("Success: " + resultObject);
        }

        function Log(msg) {
            $("#logdiv").append(msg + "<br />");
        }
    </script>
</head>
<body>
    <input id="Button1" type="button" value="Execute" onclick="CallMyService();" />
    <div id="logdiv">
    
    </div>    
</body>
</html>

Open in new window

VBBRettAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Instead of:
$("#logdiv").append(msg + "<br />");

Open in new window

Try:
$("#logdiv").prepend(msg + "<br />");

Open in new window

0
 
VBBRettAuthor Commented:
AWESOME!  Simple and it works!  Thank you very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.