UNPKG

intercooler

Version:

Making AJAX as easy as anchor tags

72 lines (54 loc) 2.44 kB
--- layout: default nav: attributes > ic-include --- <div class="container"> <div class="row"> <div class="col-md-12"> <h2><code>ic-global-include</code> - The Global Include Attribute</h2> <h3>Summary</h3> <p>The <code>ic-global-include</code> attribute tells Intercooler to include additional parameters in all requests that it makes to the server, allowing you to pass up additional UI information to the server.</p> <h3>Syntax</h3> <p>The value of the <code>ic-global-include</code> attribute can either be a CSS/JQuery element selector of elements to include in the request or a JSON object of name/value pairs to include. If it is a JSON object, it must satisfy the <a href="http://api.jquery.com/jquery.parsejson/">jQuery parseJSON() requirements</a>.</p> <p>This attribute may be placed on any element in the document and will be included with all intercooler requests.</p> <h3>Dependencies</h3> <p><code>ic-global-include</code> has no effect on dependencies.</p> <h3>Example</h3> <p>In this example, the input specifies it should be included on all requests to the server.</p> <pre> &lt;div ic-src="/update">Please Enter A Name...&lt;/div> &lt;input id="name" name="name" ic-global-include="#name"/> &lt;button ic-post-to="/update">Upload Name&lt;/button> </pre> <p>Note that the response to the button click is the content to swap in for the <em>div</em>, not the button.</p> <div class="live-demo"> <script> (function () { var name = ''; $.mockjax({ 'url': '/update', 'response' : function(settings) { if(settings.type == "GET") { if(name == "") { this.responseText = 'Please Enter A Valid Name...' } else { this.responseText = 'Great Name: ' + name } } else { var params = parseParams(settings.data); name = params['name']; } } }); })(); </script> <div ic-src="/update">Please Enter A Name...</div> <input id="name" name="name" ic-global-include="#name"/> <button class="btn btn-lg btn-primary" ic-post-to="/update">Upload Name</button> </div> </div> </div> </div>