Ajax requests with jQuery.post()
This is one of the reasons I still like jQuery.
I’m sure all the new frameworks do similar stuff, but things like this are so simple with jQuery. Anyway, jQuery.post() is a shorthand Ajax function. It’s the equivalent of doing this:
$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});
So, with it, you can send an Ajax request this easily:
var posting = $.post(url, data);
Then, handle the response like this:
posting.done(function(data) {
// Handle data here
});
Or, all together like this:
$.post( "process.php", function( data ) {
$( ".result" ).html( data );
});
It really is pretty simple.
Anyway, in my latest course I show you how to grab the form data from an HTML form, send it to a PHP script to be processed, generate a response in JSON and then handle that response in your jQuery to create an Ajax-powered quote request form on your website.
If you haven’t got into Ajax or jQuery, this is a good place to start because you get to see the whole request “loop” in a simple script that you can understand even if you’ve never done any of this before.
And, that’s along with learning about CSS Grid, CSS transitions, a little PHP and more.
Anyway, link to get no-cost access to the course here: https://skl.sh/2xM6Y3l
Later,
John