Ajax with jQuery
Ajax is a technology that sends data to the server and receives it back without reloading the page. jQuery offers several functions that make it simpler. Without jQuery, in plain JavaScript, you used to need dozens of lines of code. Here one call does the same.
<script>
function call_ajax()
{
id_ajax = $("#id_item").val();
pid_ajax = $("#pid_item").val();
$.ajax
({
url: "ajax/ajax_file.php",
type: "POST", // GET
data:
{
id_ajax_send: id_ajax,
pid_ajax_send: pid_ajax,
},
success: function(data)
{
$("#ajax_span").html(data); // put the result into the HTML element
}
});
}
</script>
<span id="ajax_span"></span>
<span onclick="call_ajax()">TODO ajax</span>
Today the same can be done without jQuery with fetch – see Loading data with fetch and async/await.