Jump to content

Converting Text File To An Array


taxmanrick

Recommended Posts

I know with the split() method, I can take a string and create an array. But I don't want to type in the string, I want to read from a text file because I will have about 65,000 elements to be put into the array. Any thoughts? Can this be done strictly through JS? I am really new to JS and HTML by the way.Thanks in advance for any suggestions.

Link to comment
Share on other sites

Here. I'll rewrite this in a more "self-commenting" fashion.

function AJAX(url, post_data) {	 var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();	 X.open(post_data ? 'PUT' : 'GET', url, false);	 X.setRequestHeader('Content-Type', 'text/html')	 X.send(post_data ? post_data : '');	 return X.responseText;}

You still have to work your way through some ternary expressions, but what it's doing is this:Get an AJAX object correct for this browser;Open the object. If there is post data to be sent, open as PUT, else open as GET. DO NOT OPEN FOR ASYNCHRONOUS COMMUNICATION.Set the request header;Send the request. If there is post data, send it, else send an empty string.Return the server's response data.

Link to comment
Share on other sites

i wrote IO to fit in a bookmarklet, so the arguments we kept as short as possible.U is the URL, V is not needed in your case. if you want to save data, V is where the data to be placed in the file at the URL goes.Don't pass anything to V.use like var str = IO("data.csv");then the file data is in the string str, which you can handle as you did before.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...