By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,805 Members | 1,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,805 IT Pros & Developers. It's quick & easy.

Push technology in javascript

P: n/a
hi all,

I need to implement a web page with a table:
the page structure i fixed, the tables field are updating from time to
time.

The table could be quite big, but just some fields change from time to
time.

I need an update delay of about 1s.

I think that the push technology could fit this requirements: do you
have some
links to examples or documentation of this type implementatiom
in HTML + JavaScript (or eventually using CGI?)

thanks for every information
giammy

Jan 30 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
gi********@gmail.com wrote:

I need to implement a web page with a table: [snip]

I think that the push technology could fit this requirements: do you
have some links to examples or documentation of this type implementatiom
in HTML + JavaScript (or eventually using CGI?)

Javascript (though it can be used elsewhere) is essentially a
web-technology used in session-based interactive operations. What that
means is that it is basically a PULL system, rather than a PUSH one. To
implement a push-based system, you would need the web page to call a
server-side javascript that would then push the data to the web page and
keep itself alive throughought the whole session.

That would, naturally, slow the server down, keep the session busy more
than need be and consume a fair bit of bandwidth. You would also need to
keep checking that the session had not been shut down from the client
side, which is what remains essentially "in-charge" of the session.
Jan 30 '06 #2

P: n/a
> Javascript (though it can be used elsewhere) is essentially a
web-technology used in session-based interactive operations. What that
means is that it is basically a PULL system, rather than a PUSH one. To
implement a push-based system, you would need the web page to call a
server-side javascript that would then push the data to the web page and
keep itself alive throughought the whole session.


I was thinking about an Ajax request, constantly receiving data
(triggered by readystatechange) and updating the table. If the
connection is interrupted, the readyState would be 4 (completed), so
giving the possibility to catch a possible connection error.

I haven't tested 'cause I don't know how to make a PUSH page, but
anyway, wouldn't it work?

Jan 30 '06 #3

P: n/a
Ronaldo Junior wrote:
Javascript (though it can be used elsewhere) is essentially a
Please provide attribution of quoted material.
web-technology used in session-based interactive operations. What that
means is that it is basically a PULL system, rather than a PUSH one. To
implement a push-based system, you would need the web page to call a
server-side javascript that would then push the data to the web page and
keep itself alive throughought the whole session.
I was thinking about an Ajax request, constantly receiving data
(triggered by readystatechange) and updating the table. If the
connection is interrupted, the readyState would be 4 (completed),
so giving the possibility to catch a possible connection error.


Definitely not.

Zeroth, it is not an "Ajax request". Ajax is a buzzword (often used
wrong), not a protocol. What you probably mean is a HTTP request via
an object implementing the IXMLHTTPRequest interface (here: x).

First, you have to understand that HTTP is not a stateful protocol (such as
e.g. FTP is). The server is allowed to end the connection immediately
after it sent the response to a client's request (using Keep-Alive can
prevent that if supported and sent by the client in intervals short
enough.)

Second, x.readyState == 4 merely indicates that the current request-response
cycle has ended. It does not mean that the connection has been severed.

Third, you can detect if a new connection could be established with that
approach or a previous one could be reused. However, in order to determine
if there was an error, you have to look for x.readyState < 4 or
x.status.test(/^(0|5\d\d)/).
I haven't tested 'cause I don't know how to make a PUSH page,
What do you mean by "PUSH page"?
but anyway, wouldn't it work?


Maybe.
PointedEars
Jan 30 '06 #4

P: n/a
Thomas 'PointedEars' Lahn wrote:
What do you mean by "PUSH page"?


Some page providing unlimited, streaming content, like a chat page. I
don't know how to make a page behave like this to test my suggestion.

Jan 30 '06 #5

P: n/a
Ronaldo Junior wrote:
Thomas 'PointedEars' Lahn wrote:
What do you mean by "PUSH page"?
Some page providing unlimited, streaming content, like a chat page.


You cannot do this exactly with HTTP alone, it required a stateful protocol.
Even a "chat page" (by which you probably mean an HTML document including a
Java applet for the chat; Java != JavaScript) is not such a real-time
application.
I don't know how to make a page behave like this to test my suggestion.


However, you can make requests repeatedly, or even better, make requests
in defined not-too-short intervals. Try this for the second approach:

function update()
{
var me = arguments.callee;

// setRequestHeader(...)

me.x.onreadystatechange = function()
{
if (me.x.readyState == 4)
{
var st = me.x.status;

// request was successful
if (st == 200)
{
// update content in one second from now
me.intv = window.setTimeout("update()", 1000);
}

// request failed
else if (st.toString().test(/^[05])/))
{
// clear interval
window.clearInterval(me.intv);

// (update content to) display error message
}
}
}

me.x.send();
}
update.x = new XMLHttpRequest();
update.x.open("GET", "http://example.com/");

// update content in one second from now
update.intv = window.setTimeout("update()", 1000);

Note that since host objects are involved, you have to do feature tests on
runtime before:

<URL:http://www.jibbering.com/faq/faq_notes/not_browser_detect.html>
HTH

PointedEars
Jan 30 '06 #6

P: n/a
Thomas 'PointedEars' Lahn wrote:
[...]
// request failed
else if (st.toString().test(/^[05])/))


Should be

else if (/^[05]/.test(st.toString()))

(as it is RegExp.prototype.test().) Note that in JavaScript 1.6
(Mozilla/5.0 rv:1.7, incl. Firefox 1.5), the explicit type conversion
is not necessary:

else if (/^[05]/.test(st))
PointedEars
Jan 30 '06 #7

P: n/a
On 2006-01-30, Ronaldo Junior <se******@gmail.com> wrote:
Javascript (though it can be used elsewhere) is essentially a
web-technology used in session-based interactive operations. What that
means is that it is basically a PULL system, rather than a PUSH one. To
implement a push-based system, you would need the web page to call a
server-side javascript that would then push the data to the web page and
keep itself alive throughought the whole session.


I was thinking about an Ajax request, constantly receiving data
(triggered by readystatechange) and updating the table. If the
connection is interrupted, the readyState would be 4 (completed), so
giving the possibility to catch a possible connection error.

I haven't tested 'cause I don't know how to make a PUSH page, but
anyway, wouldn't it work?


it'd work. the server end can be tricky. there are apparently bugs in IE
that need to be avoided too.

--

Bye.
Jasen
Feb 3 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.