Can I use ajax to call c#?

How do I display real time data which is keep on changing (sometimes miliseconds, seconds, min etc.) and data basically in form of (say in tabular format) coming into jsp page. In this jsp how can we use jquery based ajax call?

  • I have a database that update in real time, So in my JSP page that send  data, we generate a table dynamically. But that only happen when we refresh or click on refresh button present in page, what I wanted to  know that how can I make Ajax call every seconds and update that table  with data using jQuery or java script, I am not looking for any web-socket based connection I  am looking for Java Script code with jQuery that hit ajax call at every seconds to  get data from database and update the table present in JSP page.

  • Answer:

    Server side push would be the best solution for this kind of scenarios. But as you want to stick to AJAX polling then you can try JS timing events @http://www.w3schools.com/js/js_timing.asp .. $(document).ready(function () { var reload = function() { .ajax({ url: 'my servlet url', cache: false, success: function(data) { $('#table').html(data); //process data setTimeout(function() { reload(); }, 1000); } }); }; reload(); }); ** A good discussion on which timing event to use : @http://stackoverflow.com/questions/729921/settimeout-or-setinterval ** i haven't tried this, but most probably it should work. Thanks for A2A

Kamlesh Vyas at Quora Visit the source

Was this solution helpful to you?

Other answers

JSP sounds disturbing. jquery based ajax call? Please structure your question properly and in much more detail. Since you have not mentioned any constraints, here is a generic solution: What you are looking for is "ajax polling". look around for that and you will understand how to implement it. Now, since the data you are displaying is changing rapidly you would probably need a socket based solution (like websockets). I would suggest http://socket.io that runs on http://nodejs.org. To get a feel of its power and ease, try this simple tutorial that uses MySQL as a datasource -  http://markshust.com/2013/11/07/creating-nodejs-server-client-socket-io-mysql. The characteristics of this solution has the following advantage: socket.io will use a lightweight websocket to easily maintain real time communication. the client side listener will automatically update the data, you will not have to explicitly do it (in most cases). If a websocket fails to open, socket.io will fallback to ajax polling automatically. Therefore your real time requirement will not break in such a case. This solution will get you off your feet in a very short span of time (few hours to one day). There are other things you have to decide on, once you have the basic solution in place: Do you want to ensure that your code handles disconnection problems gracefully? What is the scale of data and pushing notifications are you looking at? (writing code by anticipating scaling is a bad idea however, first face the problem, then scale) If you want inspiration, check out the http://blog.fogcreek.com/the-trello-tech-stack/. Their web-app loads in half a second in a decent connection, and their "real-time data changes" are near instantaneous. There is some well engineered code there. Also, this post outlines an overview of how users' status is tracked (also important if you want to push data to specific users): http://stackoverflow.com/questions/21848413/how-does-trello-show-users-online-offline-idle-state-accurately And as my http://krishnarajpm.com says, "One solution is no solution" in engineering. Do some ground work to understand and make a choice of technology.

Ankan Adhikari

Hitesh Dholaria

You can basically create a servlet that will send you the new information in json/xml format. [can send a request variable - lastupdated], so that the servlet queries for data thats generated after [lastupdated]. On client end you can use jquery ajax to get the results in json format through this servlet and then populate the table. http://www.w3schools.com/jquery/ajax_getjson.asp You can setInterval function of javascript to update the table after every 2 to 5 seconds. http://www.w3schools.com/js/js_timing.asp Hope this approach helps you!

Ankur Jain

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.