Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

ajax post

$("#id").click(function(){
    //Read the fields
    let vnm = $('#first_name').val();
    let anm = $('#last_name').val();
    //Check if the fields are filled
    if (vnm == "")
    {
        $("#result").html("Fill in a first name!");
    }
    else if (anm == "")
    {
        $("#result").html("Enter a surname!");
    }
    //When the fields are filled, the data are to the processing page
    else
    {
        $.ajax({
            type:   "POST",
            url:    "post.php",
            data:   {"First Name": vnm,
                     "last name": anm},
            success: function (tekst) {
                $("#result").html(tekst);
            },
            error: function (request, error) {
                console.log ("ERROR:" + error);
            }
        });
    }
    //Note: form may not be 'sent'!
    return false;
});
 
PREVIOUS NEXT
Tagged: #ajax #post
ADD COMMENT
Topic
Name
4+6 =