View Full Version : Loading Json Stores from files with PHP extension

23 Apr 2012, 2:31 PM
I can't quite figure out why data won't load into my store from a php file formatted in JSON.

I've verified the output of my PHP is valid JSON via JSONLint.com, but when I try to load the store I get, "Unable to load data using the supplied configuration.
Open in Browser:"

If I copy and paste the output of my php file into a file with the .json extension, everything loads fine.

Is .php not a valid extension for loading a store? I feel like I've seen examples where people have done it.


23 Apr 2012, 8:01 PM
Any extension should work as long as the server can send correct format and content type.

Is your proxy url set? After this message, you see the proxy url which you can click to check if the url is setup correctly.
>Open in Browser:"

Also is you Url Prefix setup correctly in Project Settings?

24 Apr 2012, 6:11 AM
Thanks for taking a look at the thread....

For now I'm running on my localhost (mac os 10.7.3).

I have my ajax proxy pointing to the file ala: http://localhost/~hal1000/MyProject/jsonFeed.php, which is the main project directory.

I have set up the URL prefix in project settings and tried to provide both a relative and then an absolute path to the json.php with no luck.

In the PHP file I have also tried to set the header content type as "application/json", but there has been no change.

When I navigate to the json.php file in my browser, it loads fine. It is not formatted with line breaks, but as I indicated before, it is valid JSON according to jsonlint.com.

Just to reiterate, when I copy and paste the json.php file's contents out of browser, and into a new file named jsonFeed.json, it loads just fine.

24 Apr 2012, 6:35 AM
when you look at the source code of the browser view of your jsonFeed.php file is it exactly as needed or are there any other text bits like headers or html. You should only have pure text in the shape of the text you paste into the static file that works.

Also start with the php file in the same directory that your static file that works resides and call it the same name with he same path but simply change the extension.

24 Apr 2012, 10:27 AM
I was able to figure it out... thanks for helping troubleshoot. Viewing the source of the .php json led me in the right direction. There wasn't any html tags, but I did notice that there were some invisible line breaks in the php version that didn't appear in the static .json version.

I stripped out the line breaks in my PHP file ala:

str_replace("\n", " ", $description);
and it's now loading like a charm.

Thanks for the help. Hope this helps out someone else....