Search
 
SCRIPT & CODE EXAMPLE
 

PHP

jquery send form data to php

<form id="foo">
    <label for="bar">A bar</label>
    <input id="bar" name="bar" type="text" value="" />

    <input type="submit" value="Send" />
</form>

// Variable to hold request
var request;

// Bind to the submit event of our form
$("#foo").submit(function(event){

    // Prevent default posting of form - put here to work in case of errors
    event.preventDefault();

    // Abort any pending request
    if (request) {
        request.abort();
    }
    // setup some local variables
    var $form = $(this);

    // Let's select and cache all the fields
    var $inputs = $form.find("input, select, button, textarea");

    // Serialize the data in the form
    var serializedData = $form.serialize();

    // Let's disable the inputs for the duration of the Ajax request.
    // Note: we disable elements AFTER the form data has been serialized.
    // Disabled form elements will not be serialized.
    $inputs.prop("disabled", true);

    // Fire off the request to /form.php
    request = $.ajax({
        url: "/form.php",
        type: "post",
        data: serializedData
    });

    // Callback handler that will be called on success
    request.done(function (response, textStatus, jqXHR){
        // Log a message to the console
        console.log("Hooray, it worked!");
    });

    // Callback handler that will be called on failure
    request.fail(function (jqXHR, textStatus, errorThrown){
        // Log the error to the console
        console.error(
            "The following error occurred: "+
            textStatus, errorThrown
        );
    });

    // Callback handler that will be called regardless
    // if the request failed or succeeded
    request.always(function () {
        // Reenable the inputs
        $inputs.prop("disabled", false);
    });

});
Comment

PREVIOUS NEXT
Code Example
Php :: remove more than one space in string php 
Php :: Invalid argument supplied for foreach() in C 
Php :: switch php version ubuntu 20.04 
Php :: symfony connect rabbitMQ 
Php :: how to add column to database in laravel 
Php :: convert array to IlluminateHttpRequest 
Php :: laravel logs 
Php :: laravel ecommerce 
Php :: get field object acf 
Php :: livewire from one component to another 
Php :: how to use include in php 
Php :: Arr::only laravel 
Php :: filter wordpress 
Php :: laravel use controller function in another controller 
Php :: laravel request validation rules for create and update 
Php :: laravel documentation updateOrCreate 
Php :: wordpress enqueue if shortcode 
Php :: php slice array by key 
Php :: FPDF invoice Tutorial 
Php :: Displaying Custom Navigation Menus in WordPress Themes 
Php :: Download any version of xampp 
Php :: php - = 
Php :: Main features of php 
Php :: sass download for windows 
Php :: orderby not working with groupby laravel 
Php :: inverse hyperbolic cosine php 
Php :: global variable in laravel controller 
Php :: how to get the size of an uploaded file in laravel 
Php :: which programming languae does php resemble to? 
Php :: laravel factory pass parameter 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =