Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I'm using AJAX through the code below:

Javascript :

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 file (in asp.net) :

C#
...
...
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 !

...


This way user will wait 15 seconds for AJAX and then see the result like this:

Connecting...Reading...

Is there anyway to show the two responses independently !?

For example some way that we have the result described below:

User first see the text Connecting... and then after 10 seconds (the time that connecting longs!) the text changes and user see the text Reading... ?

Excuse my bad explanation.

Thanks in advanced.
Posted

1 solution

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.
 
Share this answer
 
Comments
Mohamad77 25-Aug-13 6:56am    
It is obvious that the time is just an example to explaining the problem! The problem IS NOT THE TIME !!! change seconds to microseconds !!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900