0

This is my code. I am trying to check if I am able to get the data from the api. Putting the api url in the browser shows the json data but console.log does not show anything.

$('document').ready(function() {
  $('#lesotho').click(function() {
    var request = $.ajax({
      url: "https://cors-anywhere.herokuapp.com/http://universities.hipolabs.com/search?country=lesotho",
      dataType: "jsonp"
    });
    request.done(function(data) {
      console.log(data);
    });
  });
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

method 'done' is calling when having successful AJAX response.

so, try this

var request = $.ajax({
  url: "https://cors-anywhere.herokuapp.com/http://universities.hipolabs.com/search? country=lesotho", 
  dataType: "jsonp"
})
request.done(function(data){
    console.log( data );
});
request.fail(function(xhr,status){
    console.log( xhr );
    console.log( status );
});

another way(i recommend this code) is

$.ajax({
  url: "https://cors-anywhere.herokuapp.com/http://universities.hipolabs.com/search? country=lesotho", 
  dataType: "jsonp" ,
  success : function(data){
    console.log( data );
  },
  error : function(xhr , status){
    console.log( status );
    console.log( xhr );
  }
});

then, you can see the log.

lucky0229
  • 36
  • 2