• Home
Name Date Size #Lines LOC

..--

.github/03-May-2024-3414

demo/03-May-2024-8871

test/03-May-2024-1,3661,108

.bower.jsonD03-May-20242 KiB6565

.gitignoreD03-May-202430 22

.travis.ymlD03-May-2024810 2726

CONTRIBUTING.mdD03-May-20243.4 KiB7839

README.mdD03-May-20244 KiB11266

bower.jsonD03-May-20241.7 KiB5756

hero.svgD03-May-20241.7 KiB3432

index.htmlD03-May-2024894 2813

iron-ajax.htmlD03-May-202415.1 KiB581483

iron-request.htmlD03-May-202414.1 KiB472408

README.md

1
2<!---
3
4This README is automatically generated from the comments in these files:
5iron-ajax.html  iron-request.html
6
7Edit those files, and our readme bot will duplicate them over here!
8Edit this file, and the bot will squash your changes :)
9
10The bot does some handling of markdown. Please file a bug if it does the wrong
11thing! https://github.com/PolymerLabs/tedium/issues
12
13-->
14
15[![Build status](https://travis-ci.org/PolymerElements/iron-ajax.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-ajax)
16
17_[Demo and API docs](https://elements.polymer-project.org/elements/iron-ajax)_
18
19## Changes in 2.0
20
21*   Promise polyfill is now a dev dependency and no longer shipped with `iron-ajax`.
22
23    `iron-ajax` uses the `Promise` API, which is not yet supported in all browsers.
24
25    The 1.x version of `iron-ajax` automatically loaded the promise polyfill. This
26    forced the application to include the polyfill, whether or not it was needed.
27
28    When using `iron-ajax` 2.x with Polymer 1.x, you must provide your own Promise polyfill,
29    if needed. For example, you could use the promise polyfill by installing it in your project:
30
31        bower install --save PolymerLabs/promise-polyfill#1 - 2
32
33    Then your app should include the promise polyfill before loading `iron-ajax`:
34
35        <link rel="import" href="bower_components/promise-polyfill/promise-polyfill-lite.html">
36
37    You can use a different promise polyfill if you need a more fully-featured implementation of
38    Promise.
39
40    For Polymer 2.x, you **do not need to provide your own Promise polyfill if  you are using
41    the web components polyfills.** Because the web components v1 APIs depend on `Promise`,
42    a promise polyfill is loaded when needed by the v1 polyfills (`web-components-lite.js` or
43    `webcomponents-loader.js`).
44
45*   New optional error information.
46
47    The `generateRequest` method returns an `iron-request` element representing the
48    request, and the request element provides a `completes` property, which is a
49    promise that completes when the request either succeeds or fails.
50
51    This version includes a new flag, `rejectWithRequest`, that modifies the error handling
52    of the `completes` promise. By default, when the promise is rejected (because the request
53    failed), the rejection callback only receives an `Error` object describing the failure.
54
55    With `rejectWithRequest` set to true, the callback receives an object with two keys, `error`,
56    the error message, and `request`, the original request that the error is related to:
57
58        let request = ironAjaxElement.generateRequest();
59        request.completes.then(function(req) {
60            // succesful request, argument is iron-request element
61            ...
62          }, function(rejected) {
63            // failed request, argument is an object
64            let req = rejected.request;
65            let error = rejected.error;
66            ...
67          }
68        )
69
70    Because this change could break existing code, `rejectWithRequest` is false by default,
71    however, in the next major release, this option will be removed and the new behavior made
72    the default.
73
74
75## &lt;iron-ajax&gt;
76
77The `iron-ajax` element exposes network request functionality.
78
79```html
80<iron-ajax
81    auto
82    url="https://www.googleapis.com/youtube/v3/search"
83    params='{"part":"snippet", "q":"polymer", "key": "YOUTUBE_API_KEY", "type": "video"}'
84    handle-as="json"
85    on-response="handleResponse"
86    debounce-duration="300"></iron-ajax>
87```
88
89With `auto` set to `true`, the element performs a request whenever
90its `url`, `params` or `body` properties are changed. Automatically generated
91requests will be debounced in the case that multiple attributes are changed
92sequentially.
93
94Note: The `params` attribute must be double quoted JSON.
95
96You can trigger a request explicitly by calling `generateRequest` on the
97element.
98
99
100
101## &lt;iron-request&gt;
102
103iron-request can be used to perform XMLHttpRequests.
104
105```html
106<iron-request id="xhr"></iron-request>
107...
108this.$.xhr.send({url: url, body: params});
109```
110
111
112