How to make a public JSON API

optikalefx · 72K views · 2010 · 7:32

Open on YouTube

Web developmentPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering beginners who need a quick example of exposing PHP data as a JSON API for JavaScript or mobile clients, including cross-domain JSONP use.

Recommended by 3 people across 3 different months, 2010 to 2019.

What it is

A 2010 screencast showing how to build a simple public JSON API in PHP and consume it from a web page with jQuery and JSONP. The presenter, from the optikalefx channel, walks through the PHP output and the client-side call in about seven minutes.

What people said

Recommends Jakub · 2010-12 · Stack Overflow · on “Connecting Php with javascript”

One issue you will be faced with is 'Cross site Scripting' with Javascript / AJAX. You can read up on it a bit here: [LINK] Also, thinking your process through, you will need sufficient javascript code to create a 'widget' on any place, and have a way to communicate BACK to your server (keep in mind PHP only runs local on your machine, so it cannot be used remotely in your javascript). You will probably need to build a JSON API (google / stack search this if needed). And enable communication from your JAVASCRIPT to the API (don't think of it as to PHP, even tho php will be your API server side language). Here is an example of a PHP JSON API (on youtube too): [this video]

Recommends nvrandow · 2012-07 · Stack Overflow · on “edit android app from browser”

Your app hat to parse/read data from your server every time it launches, for example an json-file produced by php. How to read json in android [LINK] (in this case: twitter-api) + How to make your own json(-api) [this video]

Recommends 0x_Anakin · 2013-01 · Stack Overflow · on “Cross domain iframe widget design (State of the art approach)”

Have you considered creating a simple api and using jsonp ajax client-server communication ? You wont have to worry about iframes this way... Take a look of this basic api creation tutorial in case you need more info: [this video]

Cites brass · 2015-07 · Stack Overflow · on “Get JSON variable into webpage”

Thanks for that. But my problem isnt about making php code part, my problem is about making json code... I will try to write more about that.. I would like help with making that part which is on online server X where are json code and some php code, like DB with websites (Y, Z) and its status... and into these websites (Y, Z) I check if into server X website status is disable or active. something like this [this video] but just with results for one website not all and dont show these results into consule but use it in website functions.

Cites John Doesoph · 2019-03 · Stack Overflow · on “PHP json_encode() returning Undefined to $.getJSON”

@asiby I was following this tutorial [this video] but from what you are saying I'm guessing the tutorial is incorrect. I understand some of what you're saying but I don't understand how to fix it. Can you give me more details regarding exactly what should be changed? Everything works fine if I'm only returning one row like echo $_GET['callback'] . '('.json_encode($classes[0]).')'; but when I try and return all data echo $_GET['callback'] . '('.json_encode($classes).')'; it's Undefined