Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-04-09 14:16:32
Point:500 Replies:34 POST_ID:828466USER_ID:11059
Topic:
JavaScript;;Microsoft Excel Spreadsheet Software
I get following javascript code to generate a tabel from csv file , And the link's
csv file, postcodes.csv is no issue at all. But when I try to both of mine, it is
error from firebug in Firefox. The error is "datarows(i) "is undefined"
The attached csv file from book9.csv that is my simple edit in Excel file and save as csv format,
it should be no issue , but is it still error, so I go to download from yahoo's csv file for a try
and the table.csv is also in error with the javascript code.
I check those file by notepad edit, every row in postcodes.csv and book9.csv is end with line-return
but table.csv file is end with a strange code. Please help and take a look those three csv file
Question-1 COuld you suggest any hint for the error came out ?
Question-2, How can I put css style into each cell into a table if question-1 is solved ?
I run the code and the csv file at my domain server
Please advise
Duncan
csv file, postcodes.csv is no issue at all. But when I try to both of mine, it is
error from firebug in Firefox. The error is "datarows(i) "is undefined"
The attached csv file from book9.csv that is my simple edit in Excel file and save as csv format,
it should be no issue , but is it still error, so I go to download from yahoo's csv file for a try
and the table.csv is also in error with the javascript code.
I check those file by notepad edit, every row in postcodes.csv and book9.csv is end with line-return
but table.csv file is end with a strange code. Please help and take a look those three csv file
Question-1 COuld you suggest any hint for the error came out ?
Question-2, How can I put css style into each cell into a table if question-1 is solved ?
I run the code and the csv file at my domain server
Please advise
Duncan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><html><body><script>// http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26619334.htmlfunction getData( url ){ var request = new XMLHttpRequest(); request.onreadystatechange = function() { if ( request.readyState == 4 ) { renderData( request.responseText ); } } request.open( "GET", url, true ); request.send( null );}function renderData( data ){ var dataRows = data.split( "" ); var table = document.createElement("Table"); table.border = 1; for( i = 0; i < 21; i++ ) { var tableRow = table.insertRow(i); var dataCells = dataRows[i].split(","); for( j = 0; j < dataCells.length; j++ ) { var tableCell= tableRow.insertCell(j); tableCell.innerHTML = dataCells[j]; } } document.body.appendChild( table );}getData( "http://www.freemaptools.com/download/postcodes/postcodes.csv" );</script><body><html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:
Attachment:postcodes.csvtable.csvBook9.csv
Expert: leakim971 replied at 2024-04-10 10:46:24
You're welcome! Thanks for the points!
Author: duncanb7 replied at 2024-04-10 10:41:40
Thanks for reply and part
of it is sovled
May be go to new thread
of it is sovled
May be go to new thread
Expert: leakim971 replied at 2024-04-10 09:10:31
your original post have the following zones : JavaScript, Microsoft Excel Spreadsheet Software
The purpose of this site is not to build code for people but create a huge database to help everyone searching an answer
you decide to add a new question about CSS : you should open a new thread. thanks ;)
The purpose of this site is not to build code for people but create a huge database to help everyone searching an answer
you decide to add a new question about CSS : you should open a new thread. thanks ;)
Author: duncanb7 replied at 2024-04-09 19:32:46
<head>
<style type="text/css">
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
</style>
</head>
Yes, I understood it, it set style in style tag but it set it to all or global, how to set it specify cells postion by Javascript
probably it shoud use DOM method , IS it RIght ?
<style type="text/css">
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
</style>
</head>
Yes, I understood it, it set style in style tag but it set it to all or global, how to set it specify cells postion by Javascript
probably it shoud use DOM method , IS it RIght ?
Author: duncanb7 replied at 2024-04-09 19:23:05
your link is just talking about html table stye
Expert: leakim971 replied at 2024-04-09 19:19:33
no no check my links
Author: duncanb7 replied at 2024-04-09 19:18:07
So , i give up book9.csv and solve it later,
But I mean how I set style CSS in the table by javascipt when doing csv file extraction
and I know well at html table style.
So you mean, I just do it as usally for html table style, it will show it...
For example, how I set color of cells(2,2) in table.csv to green or other color.
Is that something like that after extract table.csv and using DOM like.
document.getelementbyTage("table).item(0).rows(i).column(i).style=....
But I mean how I set style CSS in the table by javascipt when doing csv file extraction
and I know well at html table style.
So you mean, I just do it as usally for html table style, it will show it...
For example, how I set color of cells(2,2) in table.csv to green or other color.
Is that something like that after extract table.csv and using DOM like.
document.getelementbyTage("table).item(0).rows(i).column(i).style=....
Expert: leakim971 replied at 2024-04-09 18:49:50
I did not modify your
Author: duncanb7 replied at 2024-04-09 18:46:05
it is still not workign for book9.csv that is just simple file.
Could you send me back your book9.csv ?
Could you send me back your book9.csv ?
Expert: leakim971 replied at 2024-04-09 18:23:53
and/or clear your browser cache
close it or try with an other browser before retry
close it or try with an other browser before retry
Expert: leakim971 replied at 2024-04-09 18:23:09
>for( i = 0; i < 8; i++ ),, Only book9.csv is not working, Why ?
your cache probably :
Restart your webserver OR add in the url : xmlhttp.open("GET","boo9.csv?r=12345",true);
your cache probably :
Restart your webserver OR add in the url : xmlhttp.open("GET","boo9.csv?r=12345",true);
Author: duncanb7 replied at 2024-04-09 18:22:10
You mean it might be cache issue in IE or firefox
Author: duncanb7 replied at 2024-04-09 18:21:36
Why you say, all file work fine for me (check line 38 too)
Nothing wrong with line 38 I check
for( i = 0; i < 8; i++ ),, Only book9.csv is not working, Why ?
Nothing wrong with line 38 I check
for( i = 0; i < 8; i++ ),, Only book9.csv is not working, Why ?
Expert: leakim971 replied at 2024-04-09 18:19:21
1- Restart your webserver or add in the url : xmlhttp.open("GET","boo9.csv?r=12345",true);
2- Why a new question?
http://www.w3schools.com/css/css_table.asp
http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/
>and it is "not" neccessary at the same directory, for example
yes different folder is OK.
2- Why a new question?
http://www.w3schools.com/css/css_table.asp
http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/
>and it is "not" neccessary at the same directory, for example
yes different folder is OK.
Author: duncanb7 replied at 2024-04-09 18:14:54
I read it on old notepad in window XP.
I try note++ , it is fine as postcodes , line-return.
FInally
1- Why boo9.csv is still in error and notepad++ display it fine
2- Question-2, How can I put css style into each cell into a table if question-1 is solved ?
Finally from testing, if javascript code is putting at same domain and http , ajax is working.
and it is "not" neccessary at the same directory, for example
Code at : www.yourwebsite.com
File at : www.yourwbsit.com/html/file/catatlog/product
That is also working for ajax request. Am I right ?
Thanks for you at last question, anyway time to sleep for work tomorrow
I try note++ , it is fine as postcodes , line-return.
FInally
1- Why boo9.csv is still in error and notepad++ display it fine
2- Question-2, How can I put css style into each cell into a table if question-1 is solved ?
Finally from testing, if javascript code is putting at same domain and http , ajax is working.
and it is "not" neccessary at the same directory, for example
Code at : www.yourwebsite.com
File at : www.yourwbsit.com/html/file/catatlog/product
That is also working for ajax request. Am I right ?
Thanks for you at last question, anyway time to sleep for work tomorrow
Expert: leakim971 replied at 2024-04-09 18:09:22
all file work fine for me (check line 38 too)
Expert: leakim971 replied at 2024-04-09 18:08:34
book9.cvs ? or
book9.csv ?
book9.csv ?
Author: duncanb7 replied at 2024-04-09 18:06:44
For book9.cvs, you work fine at your side.
I am still in error
I am still in error
Expert: leakim971 replied at 2024-04-09 18:06:08
what's your file editor?
try notepad++
or ultraedit
linebreak differ with the OS used
try notepad++
or ultraedit
linebreak differ with the OS used
Author: duncanb7 replied at 2024-04-09 18:03:40
So why, the table is from yahoo ?
Why when I edit the table.csv, the strange code is every row, it display
never return next line.
Why when I edit the table.csv, the strange code is every row, it display
never return next line.
Expert: leakim971 replied at 2024-04-09 17:58:49
>And I believe it is still related to , line-feed and reutrn about the undefined error ?
Yes, you're right. I used only it it run fine :
Yes, you're right. I used only it it run fine :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script language="javascript"> function getData( url ) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { renderData( xmlhttp.responseText ); } } xmlhttp.open("GET","postcodes.csv",true); xmlhttp.send(); } function renderData( data ) { var dataRows = data.split( "" ); var table = document.createElement("Table"); table.border = 0.5; for( i = 0; i < dataRows.length; i++ ) { var tableRow = table.insertRow(i); var dataCells = dataRows[i].split(","); for( j = 0; j < dataCells.length; j++ ) { var tableCell= tableRow.insertCell(j); tableCell.innerHTML = dataCells[j]; } } document.body.appendChild( table ); } getData();</script></head><body></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:
Author: duncanb7 replied at 2024-04-09 17:20:33
//THe code is working for psotcodes.csv but not book9.csv and table.csv<html><body><script>// http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26619334.htmlfunction getData( url ){var xmlhttp;if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { renderData( xmlhttp.responseText ); } }xmlhttp.open("GET","http://www.yourdomain.com/table.csv",true);xmlhttp.send();}function renderData( data ){ var dataRows = data.split( "" ); var table = document.createElement("Table"); table.border = 0.5; for( i = 0; i < 41; i++ ) { var tableRow = table.insertRow(i); var dataCells = dataRows[i].split(","); for( j = 0; j < dataCells.length; j++ ) { var tableCell= tableRow.insertCell(j); tableCell.innerHTML = dataCells[j]; } } document.body.appendChild( table );}getData();</script></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:
Author: duncanb7 replied at 2024-04-09 17:17:45
Sorry I am not able to give you my domain because it is intra organization network, others could not use it
Yes, you are correct, why I said it works in javascript code to get the file at getData( "http://www.freemaptools.com/download/postcodes/postcodes.csv" ) because
it is running at my computer not at my domain. it is only okay if the code is in my PC.
And I try the w3c example http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first,
the file and code shoud be at the same domain and http:// to verfiy what you said
So I re-try it those three files, postcodes.csv(at my domain), book9.csv and table.csv download to the
same domain, only www.mydomain.com/postcodes.csv is on fire in my Firefox, other two is still in
problem with same error at var dataCells = dataRows(i).split(",");, message error is dataRows9(i) is undefined
Could you upload those three files attached above and my javascript code below to verify this.
And I believe it is still related to , line-feed and reutrn about the undefined error ?
Please help on it
Duncan
Yes, you are correct, why I said it works in javascript code to get the file at getData( "http://www.freemaptools.com/download/postcodes/postcodes.csv" ) because
it is running at my computer not at my domain. it is only okay if the code is in my PC.
And I try the w3c example http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first,
the file and code shoud be at the same domain and http:// to verfiy what you said
So I re-try it those three files, postcodes.csv(at my domain), book9.csv and table.csv download to the
same domain, only www.mydomain.com/postcodes.csv is on fire in my Firefox, other two is still in
problem with same error at var dataCells = dataRows(i).split(",");, message error is dataRows9(i) is undefined
Could you upload those three files attached above and my javascript code below to verify this.
And I believe it is still related to , line-feed and reutrn about the undefined error ?
Please help on it
Duncan
Expert: leakim971 replied at 2024-04-09 15:53:31
please, give me the url of your page
Author: duncanb7 replied at 2024-04-09 15:49:15
So if we put my javascript code at www.mydomain.com and book9.csv or table.csv at www.mydomain.com at
same http:// and same domain, it will works. But I tried, it still fail , Why ?
same http:// and same domain, it will works. But I tried, it still fail , Why ?
Accepted Solution
Expert: leakim971 replied at 2024-04-09 15:25:51
500 points GOOD
For example your pagecode is ad this address : http://www.freemaptools.com/yourpage.html
And you want to download the CSV at this address : http://www.freemaptools.com/download/postcodes/postcodes.csv
It work because we have the same protocol : http://
and the same domain : www.freemaptools.com/
Now your pagecode is ad this address : http://www.freemaptools.com/yourpage.html
but you want to download the CSV at this address : https://www.freemaptools.com/download/postcodes/table.csv
It will not work
another one :
you want to download the CSV at this address : http://subdomain.freemaptools.com/download/postcodes/Book9.csv
It will not work
And you want to download the CSV at this address : http://www.freemaptools.com/download/postcodes/postcodes.csv
It work because we have the same protocol : http://
and the same domain : www.freemaptools.com/
Now your pagecode is ad this address : http://www.freemaptools.com/yourpage.html
but you want to download the CSV at this address : https://www.freemaptools.com/download/postcodes/table.csv
It will not work
another one :
you want to download the CSV at this address : http://subdomain.freemaptools.com/download/postcodes/Book9.csv
It will not work
Author: duncanb7 replied at 2024-04-09 15:21:39
I got confused what you said about domain, protocol,
Could you explain why it works if the call to open outside link in getData( "http://www.freemaptools.com/download/postcodes/postcodes.csv" )
in term of explaination by domain and protocol ?
Could you explain why it works if the call to open outside link in getData( "http://www.freemaptools.com/download/postcodes/postcodes.csv" )
in term of explaination by domain and protocol ?
Expert: leakim971 replied at 2024-04-09 15:16:23
no, it will not work everytime if the domain and protocol is not the same
Author: duncanb7 replied at 2024-04-09 15:12:38
So you mean if the call file at my domain as caller from javascript , so both in the same domian. And
sometimes ajax xmlhttp call sometimes works soemtiomes not working , Is it what you said ?
sometimes ajax xmlhttp call sometimes works soemtiomes not working , Is it what you said ?
Expert: leakim971 replied at 2024-04-09 15:04:24
if the full url of the other files have the same domain and protocol than the page doing the ajax call no, else yes
Author: duncanb7 replied at 2024-04-09 15:00:36
So it seems the issue is not at csv file itself, it is problem with xmlhttp ajax request, Right ?
Expert: leakim971 replied at 2024-04-09 14:55:18
Author: duncanb7 replied at 2024-04-09 14:52:40
but why it works for postcodes.csv? could you explain it a little bit
Expert: leakim971 replied at 2024-04-09 14:36:52
You can't use ajax to directly download data from an other domain or using a different protocol than the page doing the call.
You have some workaround, choose one :
http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/
http://snook.ca/archives/javascript/cross_domain_aj
http://www.ajax-cross-domain.com/
http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/
You have some workaround, choose one :
http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/
http://snook.ca/archives/javascript/cross_domain_aj
http://www.ajax-cross-domain.com/
http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/