I am currently working on a mobile app project that involves fetching JSON data from a MySQL database using PHP. This is a new venture for me, so I started with a basic example to test things out. Everything works fine when the data is on the same domain, but I am encountering issues with JSON-P when trying to fetch data from a different domain. Here is the code that works on the same domain:
<html>
<head>
<title>the title</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$.getJSON('example.json', function(staff) {
document.write(staff.name);
});
});
</script>
</head>
<body>
</body>
</html>
While this code works well, I am facing challenges when I try to move the 'example.json' file to a different domain for testing. I tried adding '?callback=?' to the URL as recommended in some tutorials, but it still doesn't load anything. I modified the line to:
$.getJSON('http://www.knoxyouthgroup.org/example.json?callback=?', function(staff) {
I am unsure about the next steps to take and feel a bit stuck. Apologies for the newbie question, but any guidance would be greatly appreciated!
Our ultimate aim is to create a mobile app that fetches JSON data from a server. The data will be basic and minimal. Is it feasible to host this data on your own? I have read about REST services, but I am not sure if I can simply write a PHP script to generate JSON data. Any insights would be helpful!
Thank you for your assistance!