Rookie JS question about fetching from CSV

Discussion in 'HTML & Website Design' started by JoeKerr99, Nov 29, 2021.

  1. #1
    I'm making a line graph and when I use:

    fetch('https://data.cdc.gov/resource/w9j2-ggv5.csv')

    everything works fine. When I download the csv file and try to read from my desktop I use:

    fetch('C:\Users\JoeKe\OneDrive\Desktop\w9j2-ggv5.csv')

    and it doesn't work.

    Can someone help please?!?
     
    JoeKerr99, Nov 29, 2021 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,802
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #2
    There's a different syntax for local files. Get it by opening the csv file with chrome/edge/firefox and it'll show you how the path should be written
     
    sarahk, Nov 30, 2021 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,274
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #3
    If you're trying to open it in the browser, change the backslashes to forward slashes. C:/Users/JoeKe/OneDrive/Desktop/w9j2-ggv5.csv
     
    qwikad.com, Nov 30, 2021 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,802
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #4
    but shouldn't it also be file://
     
    sarahk, Nov 30, 2021 IP
  5. Hooman Bahreini

    Hooman Bahreini Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    You cant access local filesystem using javascript. For accessing the file using javascript, you have to upload it on a server.

    See here for more info: https://stackoverflow.com/questions/20138001/reading-files-from-hard-drive-with-javascript
     
    Hooman Bahreini, Nov 30, 2021 IP