I am trying to create a JavaScript stock ticker which pulls out live stocks. I have found a working example on JSFiddle which works relatively well and I am trying to integrate the fundamentals into my site.
The code works in JSFiddle but as soon as I take the JavaScript and place it into Dreamweaver there is a syntax error. I think it's fair to say that I am new to JavaScript/AJAX but I have tried understanding the Yahoo API which controls the stock data, which I am now fairly confident with.
Does the code need to link to an external source to work or am I missing something which is preventing me from getting the code to function outside of JSFiddle?
Any help would be appreciated as I have exhausted many hours trying to get this to work.
The code below is also available in this JS fiddle .
new Request.Stocks({
display: ['Name', 'Ask', 'Change', 'ChangeinPercent'],
sortBy: 'Name',
stocks: ['ABBN.VX', 'ATLN.VX', 'ADEN.VX', 'CSGN.VX',
'HOLN.VX', 'BAER.VX', 'LONN.VX', 'NESN.VX',
'NOVN.VX', 'CFR.VX', 'ROG.VX', 'SGSN.VX',
'UHR.VX', 'RUKN.VX', 'SCMN.VX', 'SYNN.VX',
'SYST.VX', 'RIGN.VX', 'UBSN.VX', 'ZURN.VX'],
onComplete: function(yahoo){
var result = '';
Array.each(Array.from(yahoo.query.results.quote), function(quote){
result += '<h2>{Name}</h2>
<p>{Ask} CHF,
ChangeinPercent: {ChangeinPercent},
Change: {Change}</p>'.substitute(quote);
}, this);
$('stocks').set('html', result);
},
onRequest: function(script){
$('stocks').set('text', 'Fetching...');
}
}).send();
Kind Regards, Sam
Download the lastest build here
Note: your js fiddle uses Mootools 1.3.1 i've never used mootools, but if you run into a problem try using this version
Afterwards, place it in your application folder and link it in your head like so:
<script language="javascript" type="text/javascript" src="MOOTOOLSLINK"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.