A_tom Posted November 21, 2014 Share Posted November 21, 2014 I need to be able to read a text file (csv), parse it, and then display the parsed values (numerics) in a web page. This only needs to happen on page load. The values in the file will not change more than once per day. I have spent a couple of hours trying to figure this out on my own, so I'm giving up on finding it. I found this bit of code which will read the text file and display it on the page, but I can't figure out how to break the string apart and assign it to different elements. <script>$(document).ready(function(){$("#div1").load("../clientFTP/SomeData.txt");});</script> Thanks for any assistance. Link to comment Share on other sites More sharing options...
davej Posted November 21, 2014 Share Posted November 21, 2014 HTML5 actually does offer some local file support, but only if the user manually selects or drags a file. Will you manually select this CSV file? Link to comment Share on other sites More sharing options...
A_tom Posted November 21, 2014 Author Share Posted November 21, 2014 HTML5 actually does offer some local file support, but only if the user manually selects or drags a file. Will you manually select this CSV file? No. The data is updated daily by FTP from my local computers. The file is on the server. I want to get the data and display it on the page whenever someone browses the page. It does not need to be asynchronous. I have used an ajax ticker in the past to do something like this, but I thought there might be a simpler way. After much flailing around, I put together something that does what I wanted. <script>var txt ="";var Ary ="";$.get('../clientFTP/AlligatorFin.txt', function (data) { txt = data; Ary = txt.split(","); document.getElementById("Gain").innerHTML = "Gain: "+"$"+Ary[0]; document.getElementById("Maxrunup").innerHTML = "Max RunUp: "+"$"+Ary[1]; document.getElementById("Drawdown").innerHTML = "Drawdown: "+"$"+Ary[2]; document.getElementById("Acctsize").innerHTML = "Min Account Size: "+"$K"+Ary[3];});</script> Link to comment Share on other sites More sharing options...
A_tom Posted November 21, 2014 Author Share Posted November 21, 2014 (edited) I am seeing that the above code works ok on Chrome, but not IE9. How to fix that? edit: Adding <body onload="PDataFunc()"> along with wrapping the the earlier code in the PdataFunc() fixes the IE problem. edit: On further review, I notice that once the values get loaded in IE, they never seem to update, while they do in Chrome. Ideas? edit: IE has a setting which makes this problem go away. Edited November 22, 2014 by A_tom Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now