0

I have some pages on the web which echo results like:

[{"id":"1","company":"Gaurishankar","bus_no":"JHA 12 KH 1230"},
{"id":"2","company":"Gaurishankar","bus_no":"BA 2 KH 2270"}]

I want to use this json_encode data to be used in Javascript array like:

var data = http://api.mywebsite.com/get_data.php;
for (i = 0; i<data.length; i++){
//Do something here
}

How is this possible. I know its easy but I cant make this. I am a new learner. Plz help

tika
  • 7,135
  • 3
  • 51
  • 82

1 Answers1

0

Using jQuery $.get(), it's as simple as:

$.get( "http://api.mywebsite.com/get_data.php", function( data ) {
    for (i = 0; i<data.length; i++){
        alert(data[i].id);
    }
});
Samsquanch
  • 8,866
  • 12
  • 50
  • 89