简体   繁体   中英

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

mysqldatabase ---------> 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();                            ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM