UNPKG

intercooler

Version:

Making AJAX as easy as anchor tags

62 lines (45 loc) 1.91 kB
--- layout: default nav: attributes > ic-post-to --- <div class="container"> <div class="row"> <div class="col-md-12"> <h2><code>ic-post-to</code> - The Post-To Attribute</h2> <h3>Summary</h3> <p>The <code>ic-post-to</code> attribute binds the <em>default action</em> (see below) of HTML element to a <code>POST</code> to the given URL. For example, on a button, when the button is clicked, an AJAX <code>POST</code> will be issued to the given URL.</p> {% include action_common.html %} <h3>Syntax</h3> <p>The value of the attribute should be a valid relative path (e.g. <code>ic-post-to="/foo/bar"</code>).</p> <h3>Dependencies</h3> <p><code>ic-post-to</code> implies a dependency on its path, and Intercooler will issue requests for elements whenever it detects an action that the path depends on. See <a href="/dependencies.html">Dependencies</a> for more information.</p> <h3>Example</h3> <p>Here is a simple example, with a span that depends on the updated URL:</p> <pre> &lt;button ic-post-to="/target_url">Click Me!&lt;/button> &lt;span ic-src="/target_url">You haven't clicked yet...&lt;/span> </pre> <div class="live-demo"> <script> (function () { var init = Math.floor(new Date().getTime() / 1000); $.mockjax({ 'url': '/target_url', 'response': function (settings) { if(settings.type == "GET") { this.responseText = '<span ic-src="/target_url">Thanks for clicking!</span>' } } }); })(); </script> <button class="btn btn-lg btn-primary" ic-post-to="/target_url">Click Me!</button> <span ic-src="/target_url">You haven't clicked yet...</span> </div> </div> </div> </div>