0

I can't seem to get my jquery json reader to work. I am using the following code (adapted from the flickr example on jquery's documentation):

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

</head>
<body>
<div data-role="page" id="ScheduleDay">
    <div data-role="header">
        <a href="#HomePage" data-icon="home" data-direction="reverse">Home</a>      
        <h1 id="ScheduleDayText">Schedule</h1>
    </div>
    <div data-role="content">   
        <ul data-role="listview" id="ScheduleList" data-autodividers="true">
       </ul>
    </div>
</div>
<script>
$(document).on("pageinit", "#ScheduleDay", function(){
    $.getJSON("http://oregonffa.com/EventMaster/WebService/ScheduleEvents.php",
    function(data){
        $.each(data, function(i,item){
            $("ul#ScheduleList").append('<li time="' + item.StartTime + '"><a href="javascript:viewScheduleEvent(' + item.ScheduleID + ')">' + item.Name + '</a></li>');
        });
        $("ul#ScheduleList:visible").listview('refresh');
    });
});
</script>
</body>
</html>

It doesn't appear to be reading the json feed correctly. I have created a jsfidle to show what is going on.

I'm sure that as usual, I have overlooked something in the code, but I can't figure out for the life of me where/what.

EDIT: I should point out that the json feed does parse correctly. Here is an example:

[{"ScheduleID":"1","StartTime":"3:30 PM","Name":"Registration Opens"},{"ScheduleID":"2","StartTime":"3:30 PM","Name":"State Creed Speaking Order Drawing"},{"ScheduleID":"3","StartTime":"4:30 PM","Name":"State Creed Public Speaking"},{"ScheduleID":"4","StartTime":"7:00 PM","Name":"Opening Session"}]
scholzr
  • 245
  • 8
  • 17
  • That fiddle is showing: XMLHttpRequest cannot load http://oregonffa.com/EventMaster/WebService/ScheduleEvents.php. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin. In short you can not get that resource because it is not in the same domain as the page requesting it. – Pow-Ian Feb 07 '13 at 16:59

1 Answers1

1

You can't get JSON from another host for this you have to use JSONP in jQuery

in your example console showing following error

XMLHttpRequest cannot load http://oregonffa.com/EventMaster/WebService/ScheduleEvents.php. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.

You can use this article to read about JSONP, but if you can;t modify this service then you can use a proxy page in your website,

Govind Malviya
  • 13,627
  • 17
  • 68
  • 94
  • Thank you. With a bit more googleing, I found [this post](http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) which helped me get my json feed corrected to allow for cross domain posting. – scholzr Feb 07 '13 at 17:15