473,765 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Immediately display changes to an HTML element

Hello all,

Ill try and make this short and sweet. I have the following Javascript
being executed when the user clicks a button

function myFunc()
{
-- Get some values from elements on the page

-- Send those values to the server using Ajax and retrieve a
DataTable.

-- Render the Datatable on the page for the user to view
}

This works wonderfully, except when im trying to retrieve a large
dataset (after, say 100 rows it begins to slow down. Under certain
circumstances I need to retrieve 500+). Now, im already working on
speeding up this process, but there is always going to be some waiting
if your asking for a ton of data. What im wanting to do is display a
message on the screen saying "Searching ... " and then change it to
"Complete .. " When im finished rendering the table to the screen. So I
made the following modifications

function myFunc()
{
document.getEle mentById("messa ge").innerHTM L = "Searching. ..";

-- Get some values from elements on the page

-- Send those values to the server using Ajax and retrieve a
DataTable.

-- Render the Datatable on the page for the user to view

document.getEle mentById("messa ge").innerHTM L = "Search
Complete.";
}

The "message" element is simply a <span>.

Problem is neither of those messages are being displayed until the
entire function is done.

I need to be able to display the first message right off, before
proceeding with the rest of the operation.

Any help greatly appreciated.

Feb 22 '06 #1
5 2003
Hoss wrote:
function myFunc() {
document.getEle mentById("messa ge").innerHTM L = "Searching. ..";
-- Get some values from elements on the page
-- Send those values to the server using Ajax and retrieve a
DataTable.

-- Render the Datatable on the page for the user to view
document.getEle mentById("messa ge").innerHTM L = "Search
Complete.";
} Problem is neither of those messages are being displayed until the
entire function is done.


Assuming you are correct in your analysis, one way of overcoming this
to defer the processing a bit:

function myFunc() {
document.getEle mentById("messa ge").innerHTM L = "Searching. ..";
window.setTimeo ut(restOfMyFunc , 100); }

function restOfMyFunc() {
-- Get some values from elements on the page
-- Send values to server using Ajax and retrieve a DataTable.
-- Render the Datatable on the page for the user to view
document.getEle mentById("messa ge").innerHTM L = "Search Complete.";
}

Csaba Gabor from Vienna

Feb 23 '06 #2
Hoss wrote:
<snip>
-- Send those values to the server using Ajax and retrieve a
DataTable. <snip> ... . So I made the following modifications

function myFunc()
{
document.getEle mentById("messa ge").innerHTM L = "Searching. ..";

-- Get some values from elements on the page

-- Send those values to the server using Ajax and retrieve a
DataTable.

-- Render the Datatable on the page for the user to view

document.getEle mentById("messa ge").innerHTM L = "Search
Complete.";
}

The "message" element is simply a <span>.

Problem is neither of those messages are being displayed until
the entire function is done.

I need to be able to display the first message right off,
before proceeding with the rest of the operation.


You are using synchronous XML HTTP requests, which block the browsers UI
until the response is returned, and from that point on you are busily
processing the returned data, which doesn't give the browser much room
to be updating the display until it is done.

You solve this problem by using asynchronous requests instead, as then
the browser gets the chance to update the display while the XML HTTP
request is doing its round trip to the server.

Richard.
Feb 23 '06 #3
Richard,

Thank you for your reply. However, I am making my request to the server
using Ajax ... which is by definition asynchronous. Furthermore, the
crucial line of code is being executed before the server request is
ever started. I set the HTML element of hte page, THEN Im sending a
request to the server. So im not sure what you mean ...

Assuming you were right, and I need to make an asynchronous request,
how would do go about that?

Also, the other response was quite a hack and doesnt work besides ^_^

You are using synchronous XML HTTP requests, which block the browsers UI
until the response is returned, and from that point on you are busily
processing the returned data, which doesn't give the browser much room
to be updating the display until it is done.

You solve this problem by using asynchronous requests instead, as then
the browser gets the chance to update the display while the XML HTTP
request is doing its round trip to the server.

Richard.


Feb 23 '06 #4
Hoss wrote:
Thank you for your reply. However, I am making my request to the server
using Ajax ... which is by definition asynchronous.
Not at all, it can behave like a normal or wait-for thread.

The "normal thread" will keep running and, when it finishes processing
it will "warn" you, the other one is similar to a function, it will stop
your code flow until it finishes.

Both of them have advantages, but the asynchoronous one should be chosen
always, since the synchronous one is a kind of "while(initialT ime +
delay > finalTime);"
Assuming you were right, and I need to make an asynchronous request,
how would do go about that?


The last parameter of the "open" method is a boolean which defines if
the calling will be asynchronous (true) or not (false).
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #5
Hoss wrote:
Thank you for your reply. However, I am making my request to
the server using Ajax ... which is by definition asynchronous.
You would think so, but in reality quite a lot of what is called AJAX is
using synchronous requests. Probably because its authors cannot cope
with multiple sources of asynchronous input (the user and the server) or
the possibility that responses from the server could follow a different
sequence from the requests made for them.

The symptoms you describe should not be able to exist if your requests
really are asynchronous, but if you cannot be certain I definitely
cannot without seeing your code.
Furthermore, the crucial line of code is being executed before
the server request is ever started.
That would not necessarily matter with a synchronous request.
I set the HTML element of hte page, THEN Im sending a request
to the server. So im not sure what you mean
...

Assuming you were right, and I need to make an asynchronous
request, how would do go about that?
By setting the third argument to the XML HTTP request's - open - method
to boolean true, and having an appropriate handler to deal with the
response.
Also, the other response was quite a hack and doesnt work
besides ^_^


It is a hack but it does work, if you code it right. Though it is not
the best solution to the problem.
You are using synchronous ...

<snip>

Please don't top-post to comp.lang.javas cirpt.

Richard.
Feb 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10414
by: Andy Fish | last post by:
Hi, I have a section of a web page that I want to be able to make appear and disappear with javascript, with the things below it moving up and down as appropriate. I'm not using absolute positioning or anthing fancy. I put the aforementioned section in a div: <div id="foo"> ... optional stuff in here </div>
1
5425
by: Jon W | last post by:
This is a small table with hover on the table cells. The first cell is setup to switch from div element to input element by use of display:block/none. In IE, onclick the input element is displayed correctly but it disappears if another hover is triggered. Any thoughts? Thanks,Jonny <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
19
6931
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
7
6060
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is there any other way to display/undisplay parts of web pages? TIA
2
3362
by: ruby_bestcoder | last post by:
Hi Im having problem in firefox with display:none/block. I have essentially 3 li elements. In each element there are a few nested div:s. Clicking on one of the divs, makes another div to display: block or none. Again this works in IE. In ff it has a bug. When the display is none for a div in the first li, then the next li (the one underneath) moves up to the right, looking very ugly. Is there someone who has had the
6
5122
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has a button EDIT ,which when user clicks directs him to another page (done.asp). Now the problem is that from this page (done.asp) if he clicks on the back button on the toolbar then edit.asp opens.But I don't want it to open It should show page...
2
3929
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite well, so at times it is tempting just to port parts of it over mostly as-is. In fact, one MSDN article I read suggested using straight HTML wherever possible to make the app more efficient and less resource demanding. On one page there are 2...
5
4754
by: Mel | last post by:
Is there a way of displaying the id of the element under the pointer ? Please dont ask why I need it, but I do, i found tools that needs installation that provide the same funcitonality. However, I would like to turn on this feature using a flag in my url. Something like debug=1. thanks for your help
0
2897
by: removeps-groups | last post by:
Now I'm wondering how to display 3 elements next to each other. I came up with the following solution using float:left, but would like opinions if this is the right way to go. The idea is to have an outer div, which in my example below is id="available". Inside this div is a table with float:left. Then is another div with overflow:hidden, which will be on the right. And inside this right div is the same pattern: that is, there is a...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.