Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can make use of <code>jQuery.ajax()</code> there are tons of tutorial for doing this.</p> <p><strong>Example</strong></p> <p><strong>HTML:</strong></p> <pre><code>&lt;form id="foo"&gt; &lt;label for="bar"&gt;A bar&lt;/label&gt; &lt;input id="bar" name="bar" type="text" value="" /&gt; &lt;input type="submit" value="Send" /&gt; &lt;/form&gt; </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>// variable to hold request var request; $("#foo").submit(function(event){ // 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 $inputs.prop("disabled", true); // fire off the request to /form.php var 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 occured: "+ 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); }); // prevent default posting of form event.preventDefault(); }); </code></pre> <p><strong>PHP (i.e. form.php):</strong></p> <pre><code>// you can access the values posted by jQuery.ajax // through the global variable $_POST, like this: $bar = $_POST['bar']; </code></pre> <p>and you are done.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload