Php JSONP和GET with回调-需要帮助更正错误

Php JSONP和GET with回调-需要帮助更正错误,php,jquery,json,callback,Php,Jquery,Json,Callback,这是我的JSONP文件: <?php header('Content-type: application/javascript;'); header("access-control-allow-origin: *"); header("Access-Control-Allow-Methods: GET"); //db connection detils $host = "localhost"; $user = "test"; $password = "test";

这是我的JSONP文件:

<?php
   header('Content-type: application/javascript;');
header("access-control-allow-origin: *");
header("Access-Control-Allow-Methods: GET");
  //db connection detils
  $host = "localhost";
  $user = "test";
  $password = "test";
  $database = "myradiostation1";

  //make connection
  $server = mysql_connect($host, $user, $password);
  $connection = mysql_select_db($database, $server);

  //query the database
  $query = mysql_query("SELECT *, DATE_FORMAT(start, '%d/%m/%Y %H:%i:%s') AS start, 
                                   DATE_FORMAT(end, '%d/%m/%Y %H:%i:%s') AS end FROM radiostation1");

    //loop through and return results
  for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) {
    $row = mysql_fetch_assoc($query);

    $shows[$x] = array("id" => $row["id"], "startminutes" => $row["startminutes"], "start" => $row["start"], "endminutes" => $row["endminutes"],"end" => $row["end"],"mediumname" => $row["mediumname"], "longname" => $row["longname"], "description" => $row["description"],"short_id" => $row["short_id"],"promomessage" => $row["promomessage"],"email" => $row["email"],"phonenumber" => $row["phonenumber"],"textnumber" => $row["textnumber"],"textprefix" => $row["textprefix"],"showimage" => $row["showimage"],"longdescription" => $row["longdescription"],"facebooklink" => $row["facebooklink"],"otherlink" => $row["otherlink"],"websitelink" => $row["websitelink"],"keywords" => $row["keywords"] );     
  }

  //echo JSON to page
  $response = $_GET["callback"] . "(" . json_encode($shows) . ");";
  echo $response; 

?>

我不确定到底缺少什么,但根据您提供的代码,我制作了一个JSFIDLE:

我修改了一些东西使其工作(主要是附加的东西),因为我不知道您的原始HTML文件。但我也根据你说的你想要的做了一些改变。首先,我将您的
$.getJSON
调用修改为:

$.getJSON('http://radioplayer.bauerradio.com/schedule.php?callback=?', {
          name: stationName //stationName is from the argument passed
        }, function(json){...})
它应该根据传递给的内容返回站点

LocalhostRadioStations.Schedule.ScheduleGen.init(twittiName);
为了让它更有趣,我还添加了一些从url读取的代码。在这种情况下,如果您使用
domain.htm/page?Northern FM
进入页面,它将读取
后面的文本,并将其放入
twittiName

var twittiName="Rock FM"; //default station

if(window.location.search){
   twittiName=window.location.search.substring(1)   //or window.location.hash
}
试图寻找其他电台,可能是在您的公共网站,但到目前为止,我只能测试“?摇滚+调频”。但这意味着您可以显示错误,代码可以按原样处理这些错误


因此,您的代码似乎大部分都能正常工作,但如果我遗漏了什么,请发表评论。

谢谢您的回答!看起来真的很有用。我想做的是使用我自己数据库中的代码,而不是使用链接到在线的JSON——bauerradio域(这是一个公共站点)。至于我的代码,这里是完整的链接:。我正在尝试制作我自己的版本,基本上用于本地主机测试。
var twittiName="Rock FM"; //default station

if(window.location.search){
   twittiName=window.location.search.substring(1)   //or window.location.hash
}