通過Jquery非同步擷取股票即時資料

來源:互聯網
上載者:User

標籤:

最近朋友讓我幫他做個非同步擷取資料的程式,暫時伺服器什麼都沒有,所以我就想先拿股票資料打個架構,方便後續開發和移植等事情

代碼如下:

<!--說明:股票看盤黑桃A時間:2014-04-14參考:http://www.lxway.com/240649562.htmhttp://www.lxway.com/946486042.htmhttp://www.365mini.com/page/jquery_getscript.htmhttp://blog.csdn.net/xxjoy_777/article/details/40304935http://www.jb51.net/article/54253.htm--><!DOCTYPE html><html><head>    <title></title>    <style type="text/css">        div{            height: 20px;            widows: 20px;            font-size: 26px;            font-weight: bold;        }    </style>        <script type="text/javascript" src="./jquery1.11.js"></script>    </head><body>    <div id="res"></div><br /><br /><br />    <div id="div1">        HELLO WORLD0    </div>    <div id="div2">        HELLO WORLD2    </div>    <br />    <button id="btn">click me</button><br /><br />        <script type="text/javascript">        function pageInit(){ //此方法需要在body中增加如下代碼:<body onLoad="pageInit();">         //window.setInterval("ajaxRequest()",3000);  //設定定時調用ajax的方法,單位:毫秒,1000毫秒=1秒    }         $(document).ready(function(){        var url = "http://hq.sinajs.cn/list=sh601006,sh601939,sh600016";   //返回 var hq_str_sh601006="xxxxxxx" 的形式資料。        url="http://api.money.126.net/data/feed/1000002,1000001,1000881,money.api";  //返回  _ntes_quote_callback({xxxx}); 的形式資料。        //url="http://flashquote.stock.hexun.com/Stock_Combo.ASPX?mc=1_600804&dt=T";   //返回  refreshData(xxxxxxx) 的形式資料。        getNewData(url);        var tg=self.setInterval("getNewData(‘"+url+"‘)",2000);//N毫秒重新整理一次,單位:毫秒,1000毫秒=1秒        console.log("ddd")    });    //擷取新資料    function getNewData(url)    {        var durl=url//+"&t="+Math.random();                //方式一:通過ajax的方式擷取資料        $.ajax({              cache : true,              url:url,            type: ‘GET‘,             dataType: ‘script‘,             timeout: 2000,             success: function(data, textStatus, jqXHR){                 var str = data;                str = hq_str_sh600016.split(‘,‘);                $("#res")[0].innerText=str[30]+" "+str[31]+" ajax";                console.log("fafafaf");                            }        });                        /*        //方式二:通過getScript的方式擷取資料,如果使用指令碼裡的變數必須設定$.ajaxSetup ({ cache: true });         $.ajaxSetup ({ cache: true });         $.getScript(durl,function(data){            //載入指令碼並執行擷取的指令碼資料,可以直接調用載入指令碼裡的變數等            str = hq_str_sh600016.split(‘,‘);            $("#res")[0].innerText=str[30]+" "+str[31]+" ajax";            console.log("getNewData")        });        */            }        function _ntes_quote_callback(data)    {        $("#res")[0].innerText=data[1000002].time +" callback";    }        //document.getElementById(‘btn‘).addEventListener(‘click‘, t1);         </script></body></html>

 

通過Jquery非同步擷取股票即時資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.