Here's a broad overview of how these pieces fit together:
Server vs Client
To understand all the pieces, you need to understand the difference between the server and the client.
When you open a webpage by typing an address into your browser's address bar, clicking a link, etc, your web browser sends a request to another computer sitting somewhere else where the web page you want is stored. It is essentially asking that computer for the webpage, and that computer gets to decide what you get back. We refer to this computer as the "server", since it is "serving" you the webpage.
Once the server does whatever processing it needs to do, it sends the page back to your browser. Your browser then interprets the data you get back and displays it to you in a pretty way (assuming the web designer made it pretty). We refer to your browser as the "client".
Now for the specific technologies you asked about:
PHP
PHP is referred to as a "server-side" language. This means it runs on the server to help produce the webpage that will be sent back to your browser. It runs before your browser ever sees it.
JavaScript
JavaScript is called a "client-side" language. It runs within your browser, changing things, loading new information, making the page interactive. It never runs until the page is loaded (sometimes as the page is loading, but never until your broswer begins interpreting the page). An important thing to remember is that PHP can generate JavaScript within the HTML it produces, since that's where JavaScript lives anyway.
JSON
JSON is an acronym standing for "JavaScript Object Notation". JSON is not a language; it is an element of JavaScript. JSON doesn't do anything; it is a way to represent data in an organized, useful way.
PHP can "print" a JSON object within a block of JavaScript as a way of passing data directly to the client in a useful format. PHP objects can be "dumped" to JSON using a function such as json_encode()
, which, generally speaking, returns a JSON representation of a complex array or object.
Note that JSON is much more than just an array. Please look into this more.
AJAX
AJAX is another acronym standing for "Asynchronous JavaScript And XML". (It's a somewhat misleading name, since XML is not necessarily a part of the process and is becoming increasingly rare these days, so don't worry about that part of the name.)
In short, AJAX is also not a language in and of itself; it's more of a technique within JavaScript of requesting more information/data from the server without having to reload the whole webpage.
One of the more common uses of AJAX is, like you said, to request a JSON object from the server. This is by no means the only use for AJAX, but it is a common one, especially within interactive applications.
Priority
Short answer: PHP comes before JavaScript, since it lives on the server; JSON and AJAX are elements of the JavaScript language, so they happen within JavaScript, in the browser.
Whenever your JavaScript makes an AJAX call to request some JSON from the server, there's a good change that PHP will be the language used to interpret the request and send the JSON back to your browser.
--
Hopefully that helps. You should check out resources like Zend and the Mozilla Developer Network. Here are some good places to start: