Note that there are some explanatory texts on larger screens.

plurals
  1. POAm I using jquery getJSON correctly? Nothing appears on the page in godaddy
    primarykey
    data
    text
    <p>I have a json file and an index file that uses jquery 1.10 getJSON and I'm trying to get data from the json file to display. I've got it to work on my localhost but when I move the index file to the subdomain <strong>mbsk8.zerogravity-web.com</strong> and the JSON file to the base domain <strong>www.zerogravity-web.com</strong>, the section of the page that is supposed to be updated is blank. This leads me to believe that this is a cross domain request issue.</p> <p>No values are being added to console.log either.</p> <p>Here is what I've tried to handl cross domain requests:</p> <ul> <li>Added <strong>"?callback=?"</strong> to the end of the URL</li> <li>Added a name around the JSON object: <strong>jsonResponse(JSON formatted object)</strong></li> </ul> <p>The folder structure on my godaddy account is:</p> <p><strong>json file:</strong> /LloydIce/json/skschedule.json</p> <p><strong>index file:</strong> /LloydIce/m/index.html (m) is the subdomain for mobile, using jquery mobile</p> <p><strong>Code for index.html</strong></p> <p><strong>Header section for jquery resources</strong></p> <pre><code> &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.10.2.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"&gt;&lt;/script&gt; </code></pre> <p><strong>Script section in header</strong></p> <pre><code>$(document).on('pagebeforeshow','#OpenSkate',function() { $('#publicHolder').empty(); $.getJSON('http://www.zerogravity-web.com/LloydIce/json/skschedule.json?callback=?',function(data) { $.each(data, function(index, data){ var collapsible = $('&lt;div data-role="collapsible"&gt;&lt;/div&gt;'); console.log(this.day); collapsible.append('&lt;h2&gt;' + this.day + '&lt;/h2&gt;'); $.each(data.activities, function(index, data){ if(this.type === "Public"){ console.log(this.notes + ", " + this.activity); collapsible.append('&lt;p&gt;&lt;strong&gt;' + this.activity + '&lt;/strong&gt;&lt;/p&gt;'); $.each(data.times, function(index, data){ collapsible.append('&lt;p&gt;&lt;strong&gt;Start:&lt;/strong&gt; ' + this.start + ', &lt;strong&gt;End:&lt;/strong&gt; ' + this.end + '&lt;/p&gt;&lt;/div&gt;'); }); } }); var collapsibleSet = $("#publicHolder"); collapsibleSet.append(collapsible); collapsibleSet.trigger('create'); }); }); }); </code></pre> <p><strong>Code for JSON file:</strong></p> <pre><code>jsonResults( [ { "day": "Monday", "activities": [ { "type": "Class", "notes": "Ages 3-5", "activity": "Snowbunnies 1 ", "times": [ {"start":"6:00 PM","end":"6:45 PM"} ] }, { "type": "Public", "notes": "N/A", "activity": "Open Skate ", "times": [ {"start":"11:30 AM","end":"5:00 PM"}, {"start":"7:30 PM","end":"9:30 PM"} ] } ] } ] ); </code></pre> <p><strong>chrome dev tools Network - Header tab</strong></p> <pre><code> Request URL:http://www.zerogravity-web.com/LloydIce/json/skschedule.json?callback=jQuery110206146174017339945_1388711470249&amp;_=1388711470252 Request Method:GET Status Code:200 OK Request Headersview source Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Cookie:__utma=183972909.883508564.1382898602.1388360907.1388663932.3; __utmz=183972909.1382898602.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none) Host:www.zerogravity-web.com Referer:http://mbsk8.zerogravity-web.com/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 Query String Parametersview sourceview URL encoded callback:jQuery110206146174017339945_1388711470249 _:1388711470252 Response Headersview source Accept-Ranges:bytes Access-Control-Allow-Origin:http://mbsk8.zerogravity-web.com Access-Control-Allow-Origin:http://mbsk8.zerogravity-web.com Connection:Keep-Alive Content-Length:563 Content-Type:application/json Date:Fri, 03 Jan 2014 01:48:53 GMT ETag:"233-4ef071c1e30e4" Keep-Alive:timeout=5, max=100 Last-Modified:Fri, 03 Jan 2014 01:48:42 GMT Server:Apache </code></pre> <p><strong>Chrome dev tools Network - preview and response tabs:</strong></p> <pre><code>jsonResults( [ { "day": "Monday", "activities": [ { "type": "Class", "notes": "Ages 3-5", "activity": "Snowbunnies 1 ", "times": [ {"start":"6:00 PM","end":"6:45 PM"} ] }, { "type": "Public", "notes": "N/A", "activity": "Open Skate ", "times": [ {"start":"11:30 AM","end":"5:00 PM"}, {"start":"7:30 PM","end":"9:30 PM"} ] } ] } ] ); </code></pre> <p><strong>Chrome dev tools console</strong></p> <pre><code>Uncaught ReferenceError: jsonResults is not defined skschedule.json?callback=jQuery110206146174017339945_1388711470249&amp;_=1388711470252:1 (anonymous function) </code></pre> <p><strong>If I remove the jsonResults from the JSON file the information in the Network preview tab looks like this</strong></p> <pre><code>[{day:Monday,...}] 0: {day:Monday,…} activities: [{type:Class, notes:Ages 3-5, activity:Snowbunnies 1 , times:[{start:6:00 PM, end:6:45 PM}]},…] 0: {type:Class, notes:Ages 3-5, activity:Snowbunnies 1 , times:[{start:6:00 PM, end:6:45 PM}]} activity: "Snowbunnies 1 " notes: "Ages 3-5" times: [{start:6:00 PM, end:6:45 PM}] 0: {start:6:00 PM, end:6:45 PM} end: "6:45 PM" start: "6:00 PM" type: "Class" 1: {type:Public, notes:N/A, activity:Open Skate ,…} activity: "Open Skate " notes: "N/A" times: [{start:11:30 AM, end:5:00 PM}, {start:7:30 PM, end:9:30 PM}] 0: {start:11:30 AM, end:5:00 PM} end: "5:00 PM" start: "11:30 AM" 1: {start:7:30 PM, end:9:30 PM} end: "9:30 PM" start: "7:30 PM" type: "Public" day: "Monday" </code></pre> <p>After all that, I'm still not getting the results to appear on my page.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload