I am trying to figure out what is the best way to go about creating functionality like this (
http://www.swoopo.com ) with ajax. I am just looking for the clock countdown functionality and the constant seamless update of the price. any help would be appreciated
Thanks
-bdot
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
You don’t really need AJAX for the clock functionality, you can do this with JavaScript, just google “clock countdown javascript” and you’ll find lots of samples, you can do the price update using ASP.NET AJAX to call a WebService (or PageMethod) every n
seconds to get the new prices and then use JavaScript and the DOM to show the new price to the user and restart the clock countdown, you can find samples and tutorials about calling WebServices with ASP.NET AJAX
here.
If this post helped you please remember to set it as Answer so it can help others.
If you use Ajax Timer to achieve countdown timer, it will post request each seconds. Too frequently request to server is not a good idea and it will create much more overhead on the server.
So we can use JavaScript to present the time. However, it needs to know the start time and end time from the server.
In this way, there is a little bit time span from the real server time because it needs spend a little time to get the server time. That is acceptable if veracity is not very important in the case.
Please check the below sample:
<div id="timelabel"></div>
<script type="text/javascript">
var leave =<%=seconds %>;
CounterTimer();
var interv=setInterval(CounterTimer,1000);
function CounterTimer()
{
var day = Math.floor(leave / ( 60 * 60 * 24))
var hour = Math.floor(leave / 3600) - (day * 24)
var minute = Math.floor(leave / 60) - (day * 24 *60) - (hour * 60)
var second = Math.floor(leave) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)
hour=hour<10 ? "0" + hour : hour;
minute=minute<10 ? "0" + minute : minute;
second=second<10 ? "0" + second : second;
var remain=day + " days "+hour + ":"+minute+":"+second;
leave=leave-1;
document.getElementById("timelabel").innerText=remain;
}
<>
Yes, that’s why you always need to do stress tests before going live, especially with AJAX applications, but it’s doable, in fact if you use Fiddler to check the swoopo site you’ll notice they check for new prices every second and return a relatively small
amount of data every time.
If this post helped you please remember to set it as Answer so it can help others.
bdotjones
Member
240 Points
77 Posts
Real time data with Ajax
Jul 13, 2010 07:44 PM|LINK
Hi,
I am trying to figure out what is the best way to go about creating functionality like this ( http://www.swoopo.com ) with ajax. I am just looking for the clock countdown functionality and the constant seamless update of the price. any help would be appreciated
Thanks
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
mrmercury
Star
8760 Points
1291 Posts
Re: Real time data with Ajax
Jul 13, 2010 09:46 PM|LINK
You don’t really need AJAX for the clock functionality, you can do this with JavaScript, just google “clock countdown javascript” and you’ll find lots of samples, you can do the price update using ASP.NET AJAX to call a WebService (or PageMethod) every n seconds to get the new prices and then use JavaScript and the DOM to show the new price to the user and restart the clock countdown, you can find samples and tutorials about calling WebServices with ASP.NET AJAX here.
chetan.sarod...
All-Star
66579 Points
11270 Posts
Re: Real time data with Ajax
Jul 14, 2010 02:57 AM|LINK
Please check this: http://forums.asp.net/t/1291427.aspx
http://forums.asp.net/t/1172829.aspx
If you use Ajax Timer to achieve countdown timer, it will post request each seconds. Too frequently request to server is not a good idea and it will create much more overhead on the server.
So we can use JavaScript to present the time. However, it needs to know the start time and end time from the server.
In this way, there is a little bit time span from the real server time because it needs spend a little time to get the server time. That is acceptable if veracity is not very important in the case.
Please check the below sample:
<div></div>
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
bdotjones
Member
240 Points
77 Posts
Re: Real time data with Ajax
Jul 14, 2010 03:12 PM|LINK
If I call a WebService every second,isnt that going to be resource intensive on the sever?
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"
mrmercury
Star
8760 Points
1291 Posts
Re: Real time data with Ajax
Jul 14, 2010 04:14 PM|LINK
Yes, that’s why you always need to do stress tests before going live, especially with AJAX applications, but it’s doable, in fact if you use Fiddler to check the swoopo site you’ll notice they check for new prices every second and return a relatively small amount of data every time.
bdotjones
Member
240 Points
77 Posts
Re: Real time data with Ajax
Jul 16, 2010 09:06 PM|LINK
Do you have exprience with ajax 4 new live binding feature?
If I create a service to run a query can't i just call it and use live binding for the changing price?
<div>[WebMethod]
public string GetPrice(int product_ID)
{
//connect to database and run query
//ex. select price from products
return price;
}</div>
"There are only 10 kinds of people in this world. Those who understand binary and those who don't"