I have a json file. (data.json)
{
"oneday":[[8, 5],[12, 9],[16, 1]],
"oneweek":[[1, 5],[2, 9],[3, 1],[4, 5],[5, 9],[6, 1],[7, 11]],
"onemonth":[[1, 5],[15, 9],[30, 1]]
}
A button with onclick() event.
<button onclick="test();">1D</button>
In the js file I have a function like:
function test(){
}
I want use Jquery to read this file and put this in a value. The result is like:
var oneday = [[8, 5],[12, 9],[16, 1]];
How can I write the jquery to do this.
Thanks for help!
You need to understand that javascript and by it’s nature jQuery are client side technologies. That means they operate in the browser and therefore do not have access to files on your server / local development machine unless you have included a direct reference to the file in your page markup and given the server permission to read this file.
You probably want to create a webservice or a specific page which serves JSON responses and then gather the JSON data via a $.get call in jquery within your “test()” method.