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

  }
});
2
  • Common, you almost got this yourself! :p Commented Aug 28, 2012 at 10:54
  • @PeterSzymkowski: Even I first thought he meant extract parameters from query-string when I first read it. But, is it? Commented Aug 28, 2012 at 10:57

2 Answers 2

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

alternatively you could use $.getJSON() function

Sign up to request clarification or add additional context in comments.

Comments

0
Try this:-

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.