javascript - How to play with a json object in the same file where it needs to be used? -


i doing ajax call:

var gethoursofoperation = function() {     $.ajax('hours-of-operation.json')         .done(function(data, status, xhr){             = window.moment(xhr.getresponseheader('date')).utc().format();             hours = data.hours;             holidays = data.holidays;             reftimezone = data.timezone;             // console.log(now, hours, holidays);              console.log(xhr.getresponseheader('date'));              // process date against hours , holidays             checkifopen(now);             applychatstatus(currentstatus);         })         .fail(function(){             console.log('there problem loading hours-of-operation.json');             // applychatstatus(currentstatus); // there error, go default state?         }); }; 

but need include data of file hours-of-operation.json in same file doing call, this:

var datajson = {    "timezone":"america/new_york",    "hours":[       {          "day":"sunday",          "open":"0000",          "close":"0000"       },       {          "day":"monday",          "open":"0800",          "close":"2200"       },       {          "day":"tuesday",          "open":"0800",          "close":"2200"       },       {          "day":"wednesday",          "open":"0800",          "close":"2200"       },       {          "day":"thursday",          "open":"0800",          "close":"2200"       },       {          "day":"friday",          "open":"0800",          "close":"2200"       },       {          "day":"saturday",          "open":"0000",          "close":"0000"       }    ],    "holidays":[       "2015-01-01",       "2015-01-19",       "2015-02-16",       "2015-05-25",       "2015-07-04",       "2015-09-07",       "2015-10-12",       "2015-11-11",       "2015-11-26",       "2015-12-25",       "2016-01-01",       "2016-01-18",       "2016-02-15",       "2016-05-30",       "2016-07-04",       "2016-09-05",       "2016-10-10",       "2016-11-11",       "2016-11-24",       "2016-12-25"    ] }; 

so guess line $.ajax('hours-of-operation.json') should change $.ajax(datajson) can see datajson variable containing whole data need complete ajax call.

the issue have 'data' parameter returning index.html. code first:

var gethoursofoperation = function() {     $.ajax(datajson)         .done(function(data, status, xhr){             console.log('___data___', data);                         }) }; 

that console.log('___data___', data) returns this:

enter image description here

so, can tell me difference? mean 1 call external json file, , other same data in same file doing call. so, wrong here?

if have local variable in file, can use directly.

you don't need ajax of kind.