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 6601131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:42:49+00:00 2026-05-25T18:42:49+00:00

i have the following code: (simplified for readability) C# foreach(DataRow dRow in myDS.Tables[0].Rows){ Company

  • 0

i have the following code: (simplified for readability)

C#

        foreach(DataRow dRow in myDS.Tables[0].Rows){
            Company myCompany = new Company();
            myCompany.id = int.Parse(dRow["id"].ToString());
            Companies.Add(myCompany);
        }

        JavaScriptSerializer serializer = new JavaScriptSerializer();
        Response.Write(serializer.Serialize(Companies));
        Response.End();

jQuery

$.getJSON('ajax.aspx?what=' + $('input[name="what"]').val() + '&where=' + $('input[name="what"]').val(), function (data) {
    $.each(data, function (key, val) {
        var myCompany = new function () {
            this.id = val.id;
        }
        Companies.push(myCompany);
    });
});

Now, i have another object in the C# code, which is named Cities
and i would like to return it in the same request.

something like

Response.Write(serializer.Serialize(Companies));
Response.Write(serializer.Serialize(Cities));
Response.End()

and offcourse parse it on the Client side.

how can i do something like that?

  • 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-25T18:42:49+00:00Added an answer on May 25, 2026 at 6:42 pm

    You could wrap the two properties into an anonymous object:

    var result = new { Cities = Cities, Companies = Companies };
    Response.Write(serializer.Serialize(result);
    Response.End();
    

    Or if you are using some old .NET version which doesn’t support anonymous objects you could define a wrapper class:

    public class Wrapper
    {
        public IEnumerable<Cities> Cities { get; set; }
        public IEnumerable<Company> Companies { get; set; }
    }
    

    and then:

    Wrapper result = new Wrapper();
    wrapper.Cities = Cities;
    wrapper.Companies = Companies;
    Response.Write(serializer.Serialize(wrapper);
    Response.End();
    

    Also fix your AJAX call as you are not properly url encoding your parameters:

    var data = { 
        what: $('input[name="what"]').val(), 
        where: $('input[name="what"]').val() 
    };
    $.getJSON('ajax.aspx', data, function (data) {
        $.each(data.Companies, function (index, val) {
            var myCompany = new function () {
                this.id = val.id;
            }
            Companies.push(myCompany);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I have the following 4 tables (simplified for this question): Company CompanyId | Name
I have the following code (simplified) int main() { ifstream myFile(input.txt); if(myFile.is_open()) cout<<test; }
I have the following (simplified) code: IDbConnection connection = new SQLiteConnection(GetConnectionString()); if (connection.State ==
Imagine I have the following code (simplified regarding my real context of course): <div
I am debugging some code and have encountered the following SQL query (simplified version):
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following code (simplified): ostringstream oss; oss << Text ; oss <<
I have the following (here simplified) code which I want to test with FakeItEasy
I have the following (simplified) code: var Foo = (function () { var data

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.