In this tutorial you will learn how to use jQuery to GET JSON from a URL. Recommended training (Free for 7 days) : https://juniordevelopercentral.com/tr… 👍
That’s on the assumption that the URL you are trying to send a request to actually returns a JSON response but if you have an endpoint or script that returns JSON data (or even a JSON file) then you can use jQuery to retrieve that data.
You’ll learn how to send a GET request to a PHP script locally on your computer which in the example will just return some a basic JSON structure but in reality it could be generated from your web application such as data retrieved from a database.
jQuery has traditionally relied on callback functions built in to it’s convenience functions for GET and POST AJAX requests but in the tutorial you will learn how to use jQuery’s inbuilt promise chaining system. You’ll also use arrow functions to provide the callbacks to this promise-like feature to make your code super tight and readable.
If you’d like to find out more about arrow functions take a look at the Junior Developer Central video at : https://www.youtube.com/watch?v=OzZpV…
Using the convenience functions for AJAX the jQuery GET JSON from URL process can be simplified and you can easily connect failure handling in to the chain by ensuring the .fail method has a callback provided.