how to get json data from the url in jquery?

advertisements

How to get the json array from the URL.I declare the mydata as a variable.how to get the json array into the mydata? using the following ajax

var mydata;
$.ajax({
 url: someurl,
 dataType: 'json',
 success: function() {

  }
});


var mydata;
$.ajax({
   url: someurl,
   dataType: 'json',
   success: function(data) {
      mydata = data;
      console.log(mydata);
   }
});

alternatively you could use $.getJSON() function