0

I am trying to print a json format data in HTML page. No matter what I do, I can't print the data in the html page. Here is my code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.getJSON("https://indian-courier-api-premium.vercel.app/api/delhivery/2535101029260?format=jsonp&lang=en&?callback=?", function(result){
      $.each(result, function(i, field){
        $("div").append(field + " ");
      });
    });
  });
});
</script>
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<button>Get JSON data</button>

<div></div>

</body>
</html>
Vinit Desai
  • 520
  • 1
  • 4
  • 20
  • The API you're using doesn't support JSONP nor does it support CORS. You'll have to use a proxy – Phil Oct 13 '20 at 05:40
  • what type of json format your getting from url? – ash Oct 13 '20 at 05:41
  • Please first confirm are you getting the api data or not? – Waqar Akram Oct 13 '20 at 05:48
  • @Phil Hi, How can I use proxy? I am very new at this, Could you please tell me? – scientist173 Oct 13 '20 at 15:39
  • @ash This is the data what I'm getting from the URL {"status":"success","data":[{"location":"Delhi_Airport_GW (Delhi)","detail":"Bagged at PC","date":"2020-10-13T15:04:59.306000"},{"location":"Delhi_Airport_GW (Delhi)","detail":"Bag Incoming Against Trip","date":"2020-10-13T09:35:24.181000"},.... – scientist173 Oct 13 '20 at 15:42
  • @WaqarAkram Yes, if you copy and paste the URL, you can see the JSON data. The data is from an API of a third party – scientist173 Oct 13 '20 at 15:44
  • There are two links at the top of this post with plenty of information for you to read – Phil Oct 13 '20 at 21:16
  • 1
    Thanks a lot @Phil . The proxy really did the trick. Just used https://cors-anywhere.herokuapp.com/ before the JSON URL and it worked – scientist173 Oct 14 '20 at 00:25

0 Answers0