2

The external website spits proper JSON and the code is too simple I don't know what can be wrong. I tried with get and post.

$(document).ready(function() {
  $.get("https://www.w3schools.com/jquery/demo_ajax_json.js", function(result) {
    alert(result);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
Shadow
  • 8,749
  • 4
  • 47
  • 57
kuonb
  • 198
  • 10
  • because it's cross domain - learn about CORS - also w3schools lives up to it's reputation as a crap resource - no content-type header in the response – Jaromanda X Nov 15 '17 at 02:48
  • Remember to view your console (`F12` in chrome) to view any error messages. – Shadow Nov 15 '17 at 02:49

1 Answers1

0

if you are trying to access from localhost append this line http://cors-anywhere.herokuapp.com/ else keep it like https://www.w3schools.com/jquery/demo_ajax_json.js and then use $.getJson , it will output the result as you required , also JSON.stringify the JSON data so that you can view the data in alert else [Object][Object] will be alerted

var resultUrl = 'http://cors-anywhere.herokuapp.com/'+'https://www.w3schools.com/jquery/demo_ajax_json.js';

    $.getJSON(resultUrl, function(result) {
        alert(JSON.stringify(result));
    });
Sagar
  • 475
  • 2
  • 8