-4

Lets assume I want to design a web page with stock ticker. I need my webpage to continuously as for fresh updates for stocks. How to do it ?

From my limited knowledge, AJAX wont be of much help.

What I am looking for is what sort of 'poller' can be used ?

JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – Robert Columbia Aug 04 '16 at 00:10
  • What makes you think AJAX is inappropriate? – A. Vidor Aug 04 '16 at 00:12
  • AJAX should still be used for making short-lived web service calls, not for publish/subscribe models. – JavaDeveloper Aug 04 '16 at 00:17
  • @JavaDeveloper It sounds like you are looking for [WebSockets](http://stackoverflow.com/questions/10028770/in-what-situations-would-ajax-long-short-polling-be-preferred-over-html5-websock). – A. Vidor Aug 04 '16 at 00:21

2 Answers2

1

What makes you think AJAX is inappropriate?

You can write a function that dispatches an XMLHttpRequest GET request to the relevant endpoint (let's call it /stocks), and sends the ID of the most recent datum as a query string parameter (e.g., /stocks?later_than={id}).

Your server-side code can return all data later than the ID'd datum.

You can use window.setInterval to call that function at a regular interval, or renew the request in a callback executed when the previous request receives a response.

It sounds like you might be asking about WebSockets. Here is a StackOverflow discussion of the relative merits of AJAX and WebSockets.

Here is another great StackOverflow resource covering different approaches to polling.

Community
  • 1
  • 1
A. Vidor
  • 2,502
  • 1
  • 16
  • 24
0

Ajax could be a easy and working solution. Only need to make multiple Ajax call to check for stock change.

Design your page with a div container inside. Create a javascript function which will get the stocks via AJAX, display them on the container, wait i.e. one minute and make this function call itself.

Only need to launch this beautiful function when the page load.

technico
  • 1,192
  • 1
  • 12
  • 22