我的 JSON 和 PHP 页面
我创建了一个 PHP 页面,它模拟 http://www 的外观.radioborders.com/on-air/station-schedule(仅表格部分),用于我在本地主机上设计的广播电台站点。这是一个测试站点,供我尝试 CSS/PHP/MySQL 开发。
我的页面位于 http localhost/radiostation1/mytestpage (.php 扩展名被 mod_rewrite 隐藏)
这是该页面的代码: http://pastebin.com/EvK7VzMy
但是,它链接到外部 JSON,这不是我想要的。
我正在考虑创建一个 PHP/MySQL 数组,它使用我的数据库,该数据库具有下表:
presenter (varchar, 255) image (varchar, 255) - 不确定这是否是存储它的最佳方式 showdesc(varchar,255) 播出时间(时间) 过期(时间)
我不知道如何让我的代码从本地主机上的回调中进行选择。
该网站的原始代码:
// load the schedule.
$.getJSON('http://radioplayer.bauerradio.com/schedule.php?callback=?', {
name: 'Radio Borders'
}, function(json){
// loop each show and append to our giant table.
我计划的版本:(
// load the schedule.
$.getJSON('http://localhost/myradiotest1/schedule.php?callback=?', {
name: 'Radio1FM'
}, function(json){
// loop each show and append to our giant table.
我确实有 Schedule.php 页面,但目前它只是空白,直到我弄清楚如何处理它)
我是 JSON 新手,并发现这将是一个正如我所了解的那样,它比我之前通过 PHP 从 MySQL 中提取数据的用法更具动态性(就脚本而言),我可以做得相当好。
我需要做什么才能让 JSON 回调起作用?最好的方法是什么?非常感谢任何建议,我会尝试一下,看看会发生什么。
在版权方面,我对现有 JSON 脚本的使用是合理使用,因为它仅用于我的教育用途,而不是商业分发。
I've created a page which is in PHP, it emulates the look of http://www.radioborders.com/on-air/station-schedule (only the table part) for a radio station site I designed on localhost. It's a test site, for me to try out CSS/PHP/MySQL development.
My page is at http localhost/radiostation1/mytestpage (.php extension hidden by mod_rewrite)
This is the code for the page:
http://pastebin.com/EvK7VzMy
However, it links to the external JSON, which is not what I want.
I'm thinking of creating a PHP/MySQL array, which uses my database that has the following tables:
presenter (varchar, 255)
image (varchar, 255) - not sure if that's the best way to store it
showdesc (varchar, 255)
airtime (time)
expiration (time)
I'm not sure how to get my code to select from a callback on localhost.
The original code from the site:
// load the schedule.
$.getJSON('http://radioplayer.bauerradio.com/schedule.php?callback=?', {
name: 'Radio Borders'
}, function(json){
// loop each show and append to our giant table.
My planned version:
// load the schedule.
$.getJSON('http://localhost/myradiotest1/schedule.php?callback=?', {
name: 'Radio1FM'
}, function(json){
// loop each show and append to our giant table.
(I do have the schedule.php page but it's just blank at the moment until i figure out what to do with it)
I am new to JSON and figured out that this would be a bit more dynamic (in script terms) than my previous usage of extracting data from MySQL via PHP as I've learnt about, which I can do fairly well.
What would I need to do to get a JSON callback to work and how is the best way to go about this? Any advice is much appreciated, and I'll try it out, see what happens.
In copyright terms, my usage of an existing JSON script, this is fair use, since it's only for my educational use, and not commercially distributed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 PHP 数组构建数组,然后使用
json_encode()
将数据编码为 JSON大批。现在,支持 JSONP 是微不足道的。您只需要修改代码如下:
Build your array using PHP arrays then use
json_encode()
to encode your data into a JSON array.Now, supporting JSONP at this point is trivial. You just need to modify the code as such: