c# datatable to webpage through AJAX call Error

Hi, I am trying to do this for the first time based on modifying a code snippet I found online.  I am building an html data table in my code behind embedding sql data from a c# datatable.  I am then trying to pass it to an .aspx page using an AJAX call and passing the html table string to a <div> tag.  The problem I am having is that when I breakpoint on the htmlTable string it looks good but the page is coming up with a javascript alert box saying 'error', not sure how to troubleshoot from this point or what is wrong with the code, I have pasted below, any assistance is appreciated!!!
Code Behind:
namespace WebApplication3
    public partial class Page_MF : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

        private static string connTotalOrdersCalls = ConfigurationManager.ConnectionStrings["connTotalOrdersCalls"].ConnectionString;
        public static DataTable reportDT()
            String sp_Name = "USP_TOTAL_ORDERCALLS";
            using (DataTable OrdersCalls = new DataTable())
                using (SqlConnection SQLConn = new SqlConnection(connTotalOrdersCalls))
                    using(SqlCommand SQLComm = new SqlCommand(sp_Name, SQLConn))
                        SQLComm.CommandType = CommandType.StoredProcedure;
                        //SQLComm.Parameters.Add(new SqlParameter("@Site", null);

                        SqlDataReader sql_Reader = SQLComm.ExecuteReader();
                        while (sql_Reader.Read())
                            Object[] row = {
                return OrdersCalls;
            catch (Exception)
        public static String SendToDiv()
            String htmlTable = "<table>";
            DataTable newTable = reportDT();

            for (int i = 0; i < newTable.Rows.Count; i++)
                htmlTable += "<tr>";
                for (int x = 0; x < newTable.Columns.Count; x++)
                    htmlTable += "<td>" + newTable.Rows[i][x] + "</td>";
                htmlTable += "</tr>";
            return htmlTable;

Open in new window

.ASPX Page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript">
    //on document ready event (when the dom is ready)
    $(document).ready(function () {

    function appendToDiv() {
            type: "POST",
            async: false,  
            contentType: "application/json; charset=utf-8",
            url: "Page_MF.aspx/SendToDiv",
            data: JSON.stringify({}), 
            dataType: "json",
            success: function (data) {
            error: function (result) {
    <form id="form1" runat="server">
    <div id="div-for-upload">

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
And if you change

Open in new window



Open in new window

Does it work?

Your SendToDiv function is returning a string - and you are expecting an object in your AJAX success function


What error are you getting?
Do you have a link?

Other Considerations
Are you sure you want to be appending the response - this will add a new table to the div for each call (keeping the table(s) that are already there) - if you want to update (replace) the table consider


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
replace :
            dataType: "json",
by :
            dataType: "html",

because it look like you're receiving HTML not JSON data
Scarlett72Author Commented:
Hi what actually resolved this for me was adding the following to my web.config, I think the amount of test data I was using was too large.  

        <jsonSerialization maxJsonLength="50000000">
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.