Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a rough outline of what your jQuery should look like:</p> <pre><code>$("form").submit(function(e) { e.preventDefault(); // Prevents the page from refreshing var $this = $(this); // `this` refers to the current form element $.post( $this.attr("action"), // Gets the URL to sent the post to $this.serialize(), // Serializes form data in standard format function(data) { /** code to handle response **/ }, "json" // The format the response should be in ); }); </code></pre> <p>This code snippet finds all form elements on the page and listens for a submit event from them. A form can be submit in a number ways (e.x. clicking a submit button, hitting enter, etc...), so for the sake of usability, it's best to listen for submit events directly opposed to listening for click events key on submit buttons.</p> <p>When a submit event does occurs, the code above first prevents the default browser actions (which among other things refreshes the page) by calling <a href="https://developer.mozilla.org/en/DOM/event.preventDefault"><code>e.preventDefault</code></a>. It then uses <a href="http://api.jquery.com/jQuery.post/">$.post</a> to send the form data to the url specified in the action attribute. Note that <a href="http://api.jquery.com/serialize/"><code>$.fn.serialize</code></a> is used to serialize the form data in a standard format.</p> <p>Your express code should look something like this:</p> <pre><code>var express = require('express') , app = express.createServer(); app.use(express.bodyParser()); // Automatically parses form data app.post('/Send', function(req, res){ // Specifies which URL to listen for // req.body -- contains form data }); app.listen(3000); </code></pre> <p>The documentation on <code>express.bodyParser</code> is a bit sparse, but after a bit of <a href="https://github.com/senchalabs/connect/blob/master/lib/middleware/urlencoded.js#L47">code spelunking</a> it looks like it uses <a href="https://github.com/visionmedia/node-querystring">node-querystring</a> underneath the covers.</p> <p>Hope this helps!</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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