weixin_33724059 2012-10-05 16:02 采纳率: 0%
浏览 11

慢速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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏