0

It's been few mounths i've been working on Vue.js, everything is great. But Now i'm dealing with a bigger problem, i've been tryng to solve since too much time :p

There is the problem :

I have a JSON file wich is located at : /usr/local/bin/JSONTEST/ScrapMonitorFerry_2019-12-02_14-05.json

I also have a project in Vue.js in a different folder : /usr/local/bin/MyApplication

I would like to access to the JSON file from my application and use some of the data. Even if this JSON is located in an external folder !

Do you guys have any method in mind to do that ? Is it even possible ? ** **I've found some lead on the web but none of them got me to the wanted outcome :

-using JSONP

-using Vuex

-using Webpack

-using React or Angular

I've been looking for answer for a while, I found at how to get JSON file directly when it's located in the Application folder using Ajax :

$.ajax({
url: 'ScrapMonitorFerry_2019-12-02_14-05.json',
dataType: 'json',
type: 'get',
async: false,
//cache: false,
success: function(data) {
  console.log("**************LA : *************");
  console.log(data);
  console.log("fin 1er fction");

  $(data.info).each(function(index,value) {
  console.log("on affiche value :  ");
  console.log(value.website_name);
        });

    }
});

I also find out how to acces to a JSON file located in a different local folder : using fetch method :

"use strict";
var myInit= {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json'
  },
  mode:'cors',
  cache: 'default'
};

let myRequest = new Request("./data/ScrapMonitorFerry_2019-12-02_14-05.json",myInit);

fetch(myRequest)
  .then(function(resp) {
    return resp.json();

    })
    .then(function(data) {
    console.log(data);
    }); 

Thanks for all the answers and lead you guys might right,

léo

  • you have to add the correct file path to your request – Claeusdev Jan 29 '20 at 13:24
  • @Claeusdev — File paths are useless. It's JS in the browser. It needs a URL. Under normal circumstances, nothing in `/usr/local/bin/` is going to have a URL (because that's a stupid directory to serve over HTTP) – Quentin Jan 29 '20 at 13:30
  • @Quentin that's what I thought too with saving projects in the `/bin/`. I had wanted to suggest he just copied the JSON file into the project root – Claeusdev Jan 29 '20 at 13:48

0 Answers0