I am trying to parse json data from online database with a php file link and i dont know how to do it. Generally i know that parsing json data is something like this.
<script>
var data = '{"name": "mkyong","age": 30,"address": {"streetAddress": "88 8nd Street","city": "New York"},"phoneNumber": [{"type": "home","number": "111 111-1111"},{"type": "fax","number": "222 222-2222"}]}';
var json = JSON.parse(data);
alert(json["name"]); //mkyong
alert(json.name); //mkyong
alert(json.address.streetAddress); //88 8nd Street
alert(json["address"].city); //New York
alert(json.phoneNumber[0].number); //111 111-1111
alert(json.phoneNumber[1].type); //fax
alert(json.phoneNumber.number); //undefined
</script>
But what if i create a json file with php and it has the link
www.example.com/parse.php
and i want that link to connect it with another html file in another server like
www.example2.com/parsehere.html
which has the above code without putting the json data inline, but to load it from the link of php?? Is that possible?
All im trying to do is to make inside this script to load data from a url and NOT from raw json data like the above script.
<script>
//here something to load data from a link and parse it below.
var json = JSON.parse(data);
alert(json["name"]); //mkyong
alert(json.name); //mkyong
alert(json.address.streetAddress); //88 8nd Street
alert(json["address"].city); //New York
alert(json.phoneNumber[0].number); //111 111-1111
alert(json.phoneNumber[1].type); //fax
alert(json.phoneNumber.number); //undefined
</script>