在AJAX工作的同时获取并显示AJAX响应 [英] Get and show AJAX response while AJAX is working yet

查看:84
本文介绍了在AJAX工作的同时获取并显示AJAX响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下代码使用AJAX:



Javascript:



I'm using AJAX through the code below:

Javascript :

function CallAJAX() {
    var url = "MyAJAX.ashx";
    xmlRequest.open("POST", url);
    xmlRequest.onreadystatechange = function () { ApplyUpdateCallAJAX() }
    xmlRequest.send(null);
}

function ApplyUpdateCallAJAX() {
    if (xmlRequest.readyState == 4) {
        if (xmlRequest.status == 200) {
            var response = xmlRequest.responseText;
            document.getElementById("resultDIV").innerHTML = response;
        }
    }
}





.ashx文件(在asp.net中) :





.ashx file (in asp.net) :

...
...
HttpResponse response = context.Response;
response.ContentType = "text/html";
...

response.Write("Connecting...");
// connecting to database - for example takes 10 seconds !

...
response.Write("Reading...");
// reading data from database - for example takes 5 seconds !

...





这样用户将等待15秒获得AJAX,然后看到r esult如下:



连接......阅读......



无论如何都要独立显示两个回复!?



例如某种方式我们得到如下结果:



用户首先看到文本 正在连接... ,然后在10秒后(连接多头的时间!)文本更改和用户看到文字 阅读......



请原谅我的错误解释。



谢谢高级。

推荐答案

我觉得你没有正确使用AJAX。 Ajax很受欢迎,因为它帮助开发人员缩短了用户的等待时间。此外,15秒对于用户等待来自网站的任何类型的响应来说太多了,并且在任何情况下都不建议这样做。数据库通常不需要10秒钟即可连接。我想建议您阅读有关实现AJAX的最佳实践。相信我,你的回复最少可达1秒。
I feel that you are not using the AJAX properly. Ajax was popular because it helped the developers make users wait time very less. Also, 15 seconds are too much for a user to wait for any kind of response from a website and that is not recommended in any case. Databases usually doesn't take 10 seconds to get connected. I would like to suggest you to read about best practices about implementing AJAX. Trust me you will get your response minimized up to 1 second.


这篇关于在AJAX工作的同时获取并显示AJAX响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆