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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:10:42+00:00 2026-05-31T05:10:42+00:00

This is my first time using AJAX with ASP.NET so please allow m some

  • 0

This is my first time using AJAX with ASP.NET so please allow m some rope.

I have a simple AJAX request that I wish to retuen a JSON string but ASP.NET keeps formatting the JSON string as XML

here is my code

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public string GetModels()
{
   string response;

   using (var context = new myDataModel())
   {
     var m = from model in context.ListModels select model;
     var serializer = new JavaScriptSerializer();
     response = serializer.Serialize(m);
   }

   return response;
}

this is called but returns an XML node containing my JSON string really confused

  • 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-31T05:10:42+00:00Added an answer on May 31, 2026 at 5:10 am

    This is my method for returning JSON from a webservice using ASP.NET

    [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void GetJSON()
        {
    
            DataTable dtMarkers = new DataTable();
            dtMarkers.Load(<<STORED PROCEDURE>>.GetReader());
    
            string[][] myArray = new string[dtMarkers.Rows.Count][];
            int i = 0;
            foreach (DataRow marker in dtMarkers.Rows)
            {
                myArray[i] = new string[] { marker["ID"].ToString(), marker["Title"].ToString(), marker["Blurb"].ToString(), marker["Url"].ToString(), marker["LongLatPoint"].ToString() };
                i++;
            }
    
            JavaScriptSerializer js = new JavaScriptSerializer();
            string strJSON = js.Serialize(myArray);
            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            Context.Response.Flush();
            Context.Response.Write(strJSON);
    
        }
    

    this particular example reads Googlemaps pointers from a database and returns them to the ASP.NET page for displaying on an instance of Google Maps.

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

Sidebar

Related Questions

For the first time I am using ajax with asp.net. There for I am
This is the first time ever I'm using AJAX, and I want to do
I am using $SUB for the first time and have come across this problem.
I have two update panels at my ajax page. This is first time I'm
I'm using an AJAX request to handle some part of my app that deals
I am using AJAX for the first time with PHP and mySQL. I have
I have some processing that can take up to 5+ seconds the first time
I'm using Ajax via jQuery for the first time ever. I have an html
this is my first time using StAX for parsing XML documents (still in the
Sorry, this is my first time using this forum. Apparently people can edit my

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.