慢速ajax,可轻松访问数据库

While testing out setInterval(), i had a slow load time for an ajax request. It was very simple and other pages with much more complex requests were terminating in less than a second while this very simple one is terminating after 10-12. Without using setInterval() it is still taking this long and it uses the same layout as the other pages.

Example of script:

    document.getElementById("test").innerHTML = "Starting";
    if(window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }

    else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function()
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById("test").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "/TestLive.cshtml", true);
    xmlhttp.send();

Slow server page (ASP.NET):

Response.Expires = -1;

var db = Database.Open("mydb");
string query = "select Name from Game where ID='97';";

Response.Write(db.QuerySingle(query).Name);

Example of fast:

    Response.Expires = -1;

string query = "select * from Season where Season.Game = 'Football' and Season.End > '" + DateTime.Now.Add(new TimeSpan(-8,0,0)).ToString("yyyy-MM-dd") + "';";

var db = Database.Open("mydb");
var result = db.Query(query);

Response.Write("<select id=\"chosenSeason\" onchange=\"setDraftSeason()\">");
Response.Write("<option selected=\"selected\">Choose a Season</option>");
foreach (var season in result)
{
    Response.Write("<option value=\"" + season.ID + "\">");
    Response.Write(season.Name);
    Response.Write(" (" + season.Start.ToString("dd-MM-yyyy") + " - " + season.End.ToString("dd-MM-yyyy") + ")");
    Response.Write("</option\">");
}
Response.Write("</select>");

EDIT: It seems to be related to using the layout page to access the script. all of the fast pages use the same setup though.