Examples of solutions for retrieving JSON with AJAX in JavaScript
The Delphi Books API was used to output a list of books to be displayed on the screen. The data is accessed via GET and returned as JSON.
These examples were developed on Twitch on February 1, 2022. The replay of this session can be viewed at Serial Streameur. Video excerpts are also available for each example.
Other examples have since been added, off-stream, to simplify copy/paste or the creation of simple projects without having to read the “official” documentation, which is rarely clear!
I've written some explanations on using Ajax in JavaScript on this blog.
Retrieve the list of books using jQuery's $.ajax() command. Display is done by creating HTML from jQuery.
See the video and explanations
Retrieve the list of books using jQuery's $.ajax() command. Display by cloning an HTML template in jQuery.
See the video and explanations
Use of the latest JavaScript Fetch API to retrieve data. Display by creating HTML code through DOM manipulation.
See the video and explanations
Uses Fetch API to make a GET request with two parameters to a PHP dump program on the server side.
Uses Fetch API to make a POST request with two parameters to a PHP dump program on the server side.
Use of the latest JavaScript Fetch API to retrieve data. Display data using VueJS.
See the video and explanations
Use of XMLHttpRequest to retrieve data. Display is also done by DOM manipulation.
See the video and explanations
A GET request to show how to simulate sending values as a classic HTML form would have done with a GET method.
Use the PHP API Dump program as the request destination.
GET = QUERY_String => parameters are sent in the URL.
A POST request to demonstrate how to simulate the sending of values in the same way as a classic HTML form with a POST method.
Uses the PHP API Dump program as the request destination.
POST => parameters are sent in the request body, but their encapsulation depends on the Content-Type added in the request header.
Follow my development streams of software, video games, mobile applications and websites on my Twitch channel or as replays on Serial Streameur mostly in French.
To download this code repository, we recommend using "git", but you can also download a ZIP file directly from its GitHub repository.
When I code, I work locally with XAMPP on Windows. My projects work for this stack.
There's no guarantee of compatibility with other software or versions, even though I try to keep my code clean and avoid using too many specific things.
If you detect any anomalies on earlier versions, please don't hesitate to report them so that I can test and try to correct or provide a workaround.
This source code is distributed under the AGPL 3.0 or later license.
You are generally free to use the contents of this code repository anywhere, provided that:
- you mention it in your projects
- distribute the modifications made to the files supplied in this project under the AGPL license (leaving the original copyright notices (author, link to this repository, license) which must be supplemented by your own)
- to distribute the source code of your creations under the AGPL license.
If this license doesn't suit your needs, you can purchase the right to use this project under the Apache License 2.0 or a dedicated commercial license (contact the author to explain your needs).
These source codes are provided as is, without warranty of any kind.
Certain elements included in this repository may be subject to third-party usage rights (images, sounds, etc.). They are not reusable in your projects unless otherwise stated.
If you want an answer from the project owner the best way to ask for a new feature or report a bug is to go to the GitHub repository and open a new issue.
If you found a security issue please don't report it publicly before a patch is available. Explain the case by sending a private message to the author.
You also can fork the repository and contribute by submitting pull requests if you want to help. Please read the CONTRIBUTING.md file.
If you think this project is useful and want to support it, please make a donation to its author. It will help to maintain the code and binaries.
You can use one of those services :
- GitHub Sponsors
- Ko-fi in French or in English
- Patreon
- Liberapay
- Paypal
or if you speack french you can subscribe to Zone Abo on a monthly or yearly basis and get a lot of resources as videos and articles.