Returning json from php to dashcode web application
I am building a search result page that needs to be formatted for the iPhone. I have built a browser based web application in Dashcode and input data from a php file. For this example I will call the php file test.php. Here is the basic model. (the i= is the query for the php)
web app sends i= --------> test.php --------> mysqldatabase
then
m开发者_如何学Goysqldatabase ---------> test.php ----------> JSON output
then
JSON output ------> Dashcode Browser Graphical UI
The data is getting encoded, but not loading into Dashcode's browser UI. Ideas?
It's probably the same-origin policy. Under "Run & Share" enter the domain hosting your PHP file in the "Simulate running on domain:" field (and check the checkbox next to it).
If you want to go "cross-domain" while testing within dashcode… this proxy.php
snippet allows you to enter a URL such as… http://myprivatedomain.com/proxy.php?url=https://some.twitter.jsonapi.url%8483948
and use it all, without whining, from DashCode….
<?php $filename = $_REQUEST['url'];
header('Content-Type: application/json');
ob_start();
json_encode(readfile($filename));
ob_flush(); ?>
精彩评论