AJAX
Basics
Data
DOM
Effects
Events
Forms
jQuery UI
Plug Ins
Traversing
The jQuery get()
and post()
methods are used to request data from the server with an HTTP GET or POST request.
Two commonly used methods for a request-response between a client and server are: GET and POST.
GET is basically used for just getting (retrieving) some data from the server. Note: The GET method may return cached data.
POST can also be used to get some data from the server. However, the POST method NEVER caches data, and is often used to send data along with the request.
https://www.w3schools.com/jquery/ajax_post.asp
https://api.jquery.com/jquery.post/
The $.post()
method requests data from the server using an HTTP POST request.
The $.get()
method requests data from the server with an HTTP GET request.
$.post({url}}, {data}, {callback function name }});
The first attempt will be slow. The API will have to 'wake up'.
Note: This should work but API is refusing the request. It seems to think it's not json. I wrestled with this for a couple of hours before deciding to move on. I even tried grabbing code-snippets from Postman and the issues just didn't stop. One after another. Using the ajax() method is the way to go.
$(document).ready(function ()
{
let url = "https://city-info-api-prod.azurewebsites.net/api/v1.0/cities/ce09626b-e19e-47f5-82f3-2bbf60866a47/pointsofinterest";
let data = { name: "New Jack City", description: "Where the priests are." };
let successCallBack = (data, status) => { $("#demo1").html(data + "<br /><br />Status: " + status); };
$("#btnPost").click(function ()
{
$.post(url, data, successCallBack, "json");
});
});