Click here to Skip to main content
13,251,495 members (56,128 online)
Click here to Skip to main content
Articles » Web Development » Ajax » Samples » Downloads


101 bookmarked
Posted 1 Feb 2010

A Working Example of Five Different Ways to Make jQuery AJAX Calls

, 2 Feb 2010
This article introduces a working example of five different ways to make AJAX calls using jQuery.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace jQueryFiveAjaxCalls.StudentRecordArchive
    public partial class StudentRecordsHTMLFragment : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            String ReturnJson = Request.QueryString["RETURNJSON"];
            String NoOfRecordsToRetrieve = Request.QueryString["NRECORD"];

            if (NoOfRecordsToRetrieve == null)
                NoOfRecordsToRetrieve = Request.Form["NRECORD"];

            StudentRecords Records = new StudentRecords(System.Convert.ToInt16(NoOfRecordsToRetrieve));

            DataGrid DG = new DataGrid();
            DG.CellPadding = 14;
            DG.Style.Add("font-size", "10px");
            DG.HeaderStyle.BackColor = System.Drawing.Color.Brown;
            DG.HeaderStyle.ForeColor = System.Drawing.Color.White;
            DG.HeaderStyle.Font.Bold = true;

            DG.Attributes.Add("bordercolor", "black");
            DG.DataSource = Records;

            StringBuilder SB = new StringBuilder();
            HtmlTextWriter TW = new HtmlTextWriter(new System.IO.StringWriter(SB));

            string ContentType = "text/html";
            string Content = SB.ToString();
            if (ReturnJson == "True")
                ContentType = "text/x-json";
                StringBuilder JsonSB = new StringBuilder();
                JsonSB.Append("{\"TB\": \"");
                JsonSB.Append(SB.Replace("\"", "'").Replace("\t", "").Replace("\r", "").Replace("\n", ""));
                Content = JsonSB.ToString();

            Response.ContentType = ContentType;
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            Response.OutputStream.Write(encoding.GetBytes(Content), 0, Content.Length);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dr. Song Li
United States United States
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 2 Feb 2010
Article Copyright 2010 by Dr. Song Li
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid