0

I am creating a really simple mobile app for our local track club. The app seems to be working fine when I test it on my localhost but when I change the links to point to my remote server and then package the app nothing seems to render. I am hoping that this is a really easy fix. Here is a page that I would like to populate using a JSON object into a HTML frame using Javascript.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>United Track Club</title>
<link href="jquery-mobile/jquery.mobile-1.0.1.min.css" rel="stylesheet" type="text/css"/>
<!-- This reference to phonegap.js will allow for code hints as long as the current site has been configured as a mobile application. -->

<script src="jquery-mobile/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/phonegap.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile-1.0.1.min.js" type="text/javascript"></script>

<!--a name="viewport"content="width=device-width, initial-scale=1"> -->
</head>

<body>
<div data-role="page" id="runnerListPage">
<div data-role="header">
<h1>Runners2</h1></div>
<div data-role="content">

     <ul id="runnerList" data-role="listview" data-filter="true">
     </ul>

   </div>
   <div data-role="footer" data-position="fixed">
   <div data-role="navbar">
      <ul>
        <li><a href="index.html" data-icon="home">Home</a></li>
        <li><a href="#searchListPage" data-icon="search">Search</a></li>
        <li><a href="#scheduleListPage" data-icon="grid">Schedule</a></li>
     </ul>
    </div>
    </div>
    </div>

   </body>
   </html>

Here is the JS that I created to populate the above code.

$.getJSON('http://unitedtrack.org/Mobile/TF/getrunnerlist.php', function(data){
var object = data.items,
runnerCount = object.length, 
target = document.getElementById('runnerList'),
i;

if (runnerCount>0){
    for (i =0 ; i< runnerCount; i=i+1){
        var unitrun=object[i],
        EventDt = unitrun.First_Nm,
        MeetNm = unitrun.Last_Nm;
target.innerHTML +='<li><a href="#">'+ EventDt +', ' +MeetNm +' </a></li>';
}
}
else {
    alert('there are no runners');
}
});


target.addEventListener("click",data,false);

Thank you in advance for your help.

5
  • Does the page that calls $.getJSON() also come from "unitedtrack.org" or is it on your local machine (or somewhere else)? If so, that's your problem. Commented Jan 17, 2013 at 23:49
  • The page that is being called in the $getJSON() is on the remote server. Commented Jan 17, 2013 at 23:51
  • Is this in fact your HTML code? Because you have your script calls all commented. If not, please edit your question so that people won't be confused. Commented Jan 18, 2013 at 0:00
  • So many technologies. Can't you narrow down the problem to just one of them? Commented Jan 18, 2013 at 0:17
  • I am sorry. I was cleaning up some of the code when I copied it over. The script calls are not supposed to be commented out. Commented Jan 18, 2013 at 0:28

1 Answer 1

1

You need to set proper headers on the page you are querying (e.g. http://unitedtrack.org/Mobile/TF/getrunnerlist.php).

You need to set Access-Control-Allow-Origin header. See the link for more informations about cross-origin requests.

Sign up to request clarification or add additional context in comments.

1 Comment

There is also a formatting error in the json file, it should be "items": instead of "items:"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.