由于最近网速慢的缘故,查看股票信息时网页老是打不开。这几天一直在研究ajax,于是用jquery自己做了一个自动读取新浪股票实时数据的页面
新浪的财金频道一直感觉做得很好。但由于最近网速慢的缘故,查看股票信息时网页老是打不开。这几天一直在研究ajax,于是用jquery自己做了一个自动读取新浪股票实时数据的页面。
ajax test ... function ajaxRequest()...{ $.ajax(...{ url: 'http://hq.sinajs.cn/list=sh000001,sh601939,sh600016,sh600528,sh600667,sh601390,sh601398,sh601857,sh600028', type: 'GET', dataType: 'html', timeout: 2000, success: function(response)...{ var stocks = response.split(';'); for(var i=0; i yest_f) ...{ $('#c'+i).html("" + curr_f + ""); } else if(curr_f < yest_f) ...{ $('#c'+i).html("" + curr_f + ""); } else ...{ $('#c'+i).html(curr_f); } $('#d'+i).html(tday_f); $('#e'+i).html(yest_f); if(temp_f > 0) ...{ $('#f'+i).html("" + temp_f.toFixed(2) + ""); $('#g'+i).html("" + ((temp_f / yest_f) * 100).toFixed(2) + " % "); } else if(temp_f < 0) ...{ $('#f'+i).html("" + temp_f.toFixed(2) + ""); $('#g'+i).html("" + ((temp_f / yest_f) * 100).toFixed(2) + " % "); } else ...{ $('#f'+i).html(temp_f.toFixed(2)); $('#g'+i).html(((temp_f / yest_f) * 100).toFixed(2) + " % "); } $('#h'+i).html(temp3.split(',')[4]); $('#i'+i).html(temp3.split(',')[5]); } } }); } function pageInit() ...{ window.setInterval("ajaxRequest()",3000); } ... .tr_cls {...}{ height:30px; font-size:16px; font-family:"Times New Roman", Times, serif; background-color:#FFFFCC }
登录后复制
习惯用prototype的,把脚本部分的代码替换一下即可。
复制代码 代码如下:
... 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 yest_f) ...{ $('c'+i).innerHTML = "" + curr_f + ""; } else if(curr_f < yest_f) ...{ $('c'+i).innerHTML = "" + curr_f + ""; } else ...{ $('c'+i).innerHTML = curr_f; } $('d'+i).innerHTML = tday_f; $('e'+i).innerHTML = yest_f; if(temp_f > 0) ...{ $('f'+i).innerHTML = "" + temp_f.toFixed(2) + ""; $('g'+i).innerHTML = "" + ((temp_f / yest_f) * 100).toFixed(2) + " %"; } else if(temp_f < 0) ...{ $('f'+i).innerHTML = "" + temp_f.toFixed(2) + ""; $('g'+i).innerHTML = "" + ((temp_f / yest_f) * 100).toFixed(2) + " %"; } else ...{ $('f'+i).innerHTML = temp_f.toFixed(2); $('g'+i).innerHTML = ((temp_f / yest_f) * 100).toFixed(2) + " % "; } $('h'+i).innerHTML = temp3.split(',')[4]; $('i'+i).innerHTML = temp3.split(',')[5]; } } function pageInit() ...{ window.setInterval("ajaxRequest()",3000); }
登录后复制
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
浅析Asp.net MVC 中Ajax的使用
JQuery Ajax动态生成Table表格
Ajax在请求过程中显示进度的简单实现
以上就是使用ajax技术无刷新动态调用新浪股票实时数据的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2756993.html