-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,644
  • 10
  • 40
  • 64

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
  • 22,194
  • 16
  • 64
  • 99
Om3ga
  • 30,465
  • 43
  • 141
  • 221
0
Try this:-

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