-1

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() {

  }
});
User
  • 1,564
  • 9
  • 39
  • 62

2 Answers2

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

alternatively you could use $.getJSON() function

Robin Maben
  • 20,994
  • 16
  • 62
  • 96
Om3ga
  • 26,989
  • 41
  • 135
  • 210
0
Try this:-

    ***$.ajax({
     url: someurl,
     dataType: 'json',
     success: function(mydata) {
foreach(var data in mydata){
//do something.....    
}
      },
failure: function()
{
//error message
}
    });***