Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:33:39+00:00 2026-05-29T09:33:39+00:00

I have the following JQUERY code that I’m expecting to return 3 json results

  • 0

I have the following JQUERY code that I’m expecting to return 3 json results to the console. What’s happening is I’m getting 3 copies of the results of the first return.

so for example I’m trying to see filename’s, and I’m getting back “first name, first name, first name” instead of “first name, second name, third name”

here’s my code:

$.ajax({
    type: "POST",
    url: "front.aspx/GetData",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        var obj = msg.d;
        $.each(obj, function(index, value){ 
            console.log(value);    
        });
    }
});

what am I doing wrong with the each function?

I don’t think you need my CS code to tell me what I’m doing wrong, but incase you do, here it is:

public class LoadData {
    public string filename;
    public string date;
    public string filetype;
    public Int32 height;
    public Int32 width;
    public string uploadGroup;
    public string title;
    public string uniqueID;
    public string uploader;
    public string uniqueIDnoExt;
}

[WebMethod]
public static List<LoadData> GetData() {
    LoadData b = new LoadData();
    List<LoadData> info = new List<LoadData>();
    SqlDataReader reader;
    string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
    SqlConnection connection = new SqlConnection(connectionString);
    connection.Open();

    SqlCommand command = new SqlCommand("SELECT * FROM uploads ORDER BY id DESC", connection);
    command.Parameters.Add(new SqlParameter("uploader", "anonymous"));

    reader = command.ExecuteReader();

    while (reader.Read()) {
    b.filename = reader.GetString(1);
    b.date = reader.GetSqlDateTime(3).ToString();
    b.filetype = reader.GetString(4);
    b.height = (Int32)reader.GetSqlInt32(5);
    b.width = (Int32)reader.GetSqlInt32(6);
    b.uploadGroup = reader.GetString(7);
    b.title = reader.GetString(8);
    b.uniqueID = reader.GetString(9);
    b.uploader = reader.GetString(10);
    b.uniqueIDnoExt = reader.GetString(12);

    info.Add(b);
    }

    return info;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:33:40+00:00Added an answer on May 29, 2026 at 9:33 am

    Move this line

    LoadData b = new LoadData();
    

    inside the loop.

    while (reader.Read()) {
    LoadData b = new LoadData();
    
    b.filename = reader.GetString(1);
    b.date = reader.GetSqlDateTime(3).ToString();
    b.filetype = reader.GetString(4);
    b.height = (Int32)reader.GetSqlInt32(5);
    b.width = (Int32)reader.GetSqlInt32(6);
    b.uploadGroup = reader.GetString(7);
    b.title = reader.GetString(8);
    b.uniqueID = reader.GetString(9);
    b.uploader = reader.GetString(10);
    b.uniqueIDnoExt = reader.GetString(12);
    
    info.Add(b);
    }
    

    The way you have it now you make only one line of data. The List<> holds the reference, it does not recreate them. So if you’re not making new data, you’re not inserting any new data (as it is now). You’re just adding first one in memory, and then changing the values.

    Also you can read :
    http://en.wikipedia.org/wiki/Linked_list

    By the way.

    You have left open many things, you will soon end up without resources. Use the using keyword on the objects that need to be closed. And, for speed, use a static string (to read only) on the connection string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following jQuery code that stops the user selecting text in a
Hallo, I have following jquery code for calling ASP.NET MVC controller method that is
I have the following JQuery code that processes a GET request upon page load:
Hi I have the following jQuery code that splits some content after the second
I have a jQuery slideshow code that works fine with the following HTML structure:
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I have the following jQuery code that uses the scrollTo and localScroll plugins from
I have the following jQuery code (similar to this question ) that works in
this is my first question here. I have the following jquery code: $(document).ready(function(){ $(a).click(function(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.