0

This the working script.

 $.getJSON('http://time.jsontest.com', function(data) {
    var text = `Date: ${data.date}<br>
                Time: ${data.time}<br>
                Unix time: ${data.milliseconds_since_epoch}`
                
    $(".mypanel").html(text);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mypanel"></div>

In the above script I replaced the URL as http://abacusshopee.biz/COMPUTERS/test.json then the Code is not working.

The contents of the JSON file as follows.

{
   "date": "09-02-2020",
   "milliseconds_since_epoch": 1599029414853,
   "time": "06:50:14 AM"
}

I used same json files for fetching data. Both the files contains. same data.

My problem is that when test with the first script, it is working. But when try with the second one (using 'http://abacusshopee.biz/COMPUTERS/test.json') the script not working.

Tân
  • 1
  • 15
  • 56
  • 102
  • Please start with basic debugging. Your browser usually tells you exactly what's wrong. In this case it is a cross-origin request issue: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://abacusshopee.biz/COMPUTERS/test.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)." – str Sep 02 '20 at 08:20
  • Thanks. Will you suggest how to solve cross-origin request issue? – user1816193 Sep 03 '20 at 05:21

1 Answers1

-1

I have solved this issue. It is a CORS issue. I have changed the url as 'https://cors-anywhere.herokuapp.com/http://abacusshopee.biz/COMPUTERS/test.json'. The test.json file opened via proxy link https://cors-anywhere.herokuapp.com.

Thanks for comments.