This is driving me crazy. I wrote a php api file and stored it on my server. When I run the url directly the JSON results are perfectly echoed to the screen, with no problem. However, when I attempt to access the results from another domain (e.g. Cross domain) I can not get the values to show. The screen is still blank. I hope this is making sense. I'm wondering if there is something wrong with my javascript call below. This is really becoming a royal pain.
Any help will be greatly appreciated.
The code below:
Note:
//Example of what the JSON results would look like
{
"name": "John Doe",
"url": "http://www.adomain.com",
"created": "A DATE HERE"
}
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml ">
<html>
<head>
<title>API JSON Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
var timeService = "http://api.MYDOMAIN.com/api.php?key=abc&num=1&format=json&callback=?";
$.getJSON(timeService, function(data) {
$('showdata').html("<p>ulore="+data.name+" url="+data.url+" created="+data.created+"</p>");
});
});
</script>
<div id="showdata"></div>
</body>
</html>