Use AJAX technology without refreshing dynamic call Sina stock Real time data _ajax related

Source: Internet
Author: User
Tags setinterval

Sina's financial channel has always felt good. But because of the recent slow speed, the Web page is always open when viewing stock information. have been studying Ajax for several days, so I made a page with jquery to automatically read real-time data on Sina stock.

 

Accustomed to using prototype, replace the script part of the code.
Copy code code as follows:

<script type= "Text/javascript" src= "prototype.js" ></script> <script type= "Text/javascript" .... function Ajaxrequest () ... {var myajax = new Ajax.request (' http://hq.sinajs.cn/list=sh000001,sh601939,sh600016,sh600528,sh600667,sh601390, sh601398,sh601857,sh600028 ', ... 
{method: ' Get ', oncomplete:setdata}); } function SetData (response) ... 
{var contents = Response.responsetext; 
var stocks = Contents.split (';'); for (var i=0; i<stocks.length-1; i++) ... 
{var content = Stocks[i]; 
var temp1 = content.split (' = ') [0]; 
var temp2 = content.split (' = ') [1]; 
var code = TEMP1.SUBSTR (temp1.length-6, 6); 
var Temp3 = temp2.replace (' "', '); 
var name = Temp3.split (', ') [0]; 
var tday_f = Temp3.split (', ') [1]; 
var yest_f = Temp3.split (', ') [2]; 
var curr_f = Temp3.split (', ') [3]; 
var temp_f = Curr_f-yest_f; 
$ (' a ' +i). InnerHTML = code; 
$ (' B ' +i). InnerHTML = name; 
$ (' C ' +i). InnerHTML = Curr_f; if (Curr_f > Yest_f) ... {$ (' C ' +i). InnerHTML = "<font color= ' Red ' > "+ curr_f +" </font> "; else if (Curr_f < Yest_f) ... 
{$ (' C ' +i). InnerHTML = "<font color= ' green ' >" + curr_f + "</font>"; else ... 
{$ (' C ' +i). InnerHTML = Curr_f; 
} $ (' d ' +i). InnerHTML = Tday_f; 
$ (' E ' +i). InnerHTML = Yest_f; if (Temp_f > 0) ... 
{$ (' F ' +i). InnerHTML = "<font color= ' Red ' >" + temp_f.tofixed (2) + "</font>"; 
$ (' G ' +i). InnerHTML = "<font color= ' Red ' >" + ((temp_f/yest_f) *). ToFixed (2) + "</font>%"; else if (Temp_f < 0) ... 
{$ (' F ' +i). InnerHTML = "<font color= ' green ' >" + temp_f.tofixed (2) + "</font>"; 
$ (' G ' +i). InnerHTML = "<font color= ' green ' >" + ((temp_f/yest_f) *). ToFixed (2) + "</font>%"; else ... 
{$ (' F ' +i). InnerHTML = temp_f.tofixed (2); 
$ (' G ' +i). InnerHTML = ((temp_f/yest_f) *). ToFixed (2) + "%"; 
} $ (' H ' +i). InnerHTML = Temp3.split (', ') [4]; 
$ (' I ' +i). InnerHTML = Temp3.split (', ') [5]; }} function Pageinit () ... 
{Window.setinterval ("ajaxrequest ()", 3000); };/script> 

Of course, the page part can be automatically generated by the script, as well as the page dynamically increase and decrease stock information and other functions, and so on later modify it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.