Code Monkey home page Code Monkey logo

iron-ajax's People

Contributors

addyosmani avatar andybons avatar aomarks avatar bicknellr avatar brendankenny avatar cdata avatar dependabot[bot] avatar dfreedm avatar dmdreon avatar e111077 avatar ebidel avatar elliottsj avatar frankiefu avatar garlicnation avatar gronke avatar jhuckabee avatar jklein24 avatar justinfagnani avatar kevinpschaaf avatar mbleigh avatar notwaldorf avatar rictic avatar rikbrowning avatar rnicholus avatar samuelli avatar sorvell avatar stramel avatar tedium-bot avatar timluq avatar zoramite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iron-ajax's Issues

The request using POST method isn't working

I'm using iron-ajax 1.0.2, but when i use this:

 <iron-ajax
    id="loginControl"
    handle-as="json"
    method="POST"
    on-response="getResult"
    on-error="getError"
    params='{"username":"test", "passowrd":"test2"}'
    url="http://localhost/user/login"
>
</iron-ajax>

doesn't send any parm to the server.
I had check with jquery, byy example that the url works properly, but using iron-ajax it doesn't.

i'm missing something? or there is a bug on the code.

Remove use of `configure`

PSA: we are going to (soon) remove the general configure function, which was the predecessor to value in properties, and is pretty much an unnecessary duplicate API at this point. Configuring default property values should be moved to properties: { prop: { value: ... } }. It also looks like a pattern emerged to bind event listener functions to instance methods in configure; this can just be done in created instead.

Problem with params

Hi!

How to pass params from properties?
In this case, movieId:

Polymer({
      is: "yts-movie",
      movieId: 15,
      ready: function() {
        console.log('ready yts-movie')
      },
      ytsMovieResponse: function(event, result){
          console.log(result.response)
      }
});
<iron-ajax
        auto
        url="https://yts.to/api/v2/movie_details.json"
        params='{"movie_id": "{{ movieId }}" }'
        handle-as="json"
        on-response="ytsMovieResponse"
        debounce-duration="0">
</iron-ajax>

request HTTP is

https://yts.to/api/v2/movie_details.json?0=%7B&1=%22&2=m&3=o&4=v&5=i&6=e&7=_&8=i&9=d&10=%22&11=%3A

params breaking while being appended to url

My iron-ajax component has the following property values:

url="?contacts&m=login"
method="GET"
//The params are set in javascript
iron_ajax.params = {"full_names":googleUser.getBasicProfile().getName(),"access_token":googleUser.getAuthResponse().id_token,"image":googleUser.getBasicProfile().getImageUrl()}

//When I dump the $_GET variable (json encoded), this is what it returns:

{"c":"contacts","m":"login?full_names=Firstname Lastname","access_token":"e........."}

๐Ÿ˜‘

I then went and changed the question '?' mark here:
https://github.com/PolymerElements/iron-ajax/blob/master/iron-ajax.html#L306
to an ampersand '&' and now my dump looks like this:

{"c":"contacts","m":"login","full_names":"Firstname Lastname","access_token":"eyJh.......}

๐Ÿ˜ƒ
That seemed to have solved the problem, you might want to check that out.

Support making JSONP requests

Hi... Please look the below code

<iron-ajax
    auto
    url="https://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=8&pz=1&cf=all&ned=in&hl=en&topic=tc"
    handle-as="json"
    last-response="{{ajaxResponse}}"></iron-ajax>

    <template is="dom-repeat" items="{{ajaxResponse.responseData.results}}">
          <paper-material elevation="1" class="paper-font-body2">
                <h1>{{item.title}}</h1>
                <iron-image src="[[item.image.url]]" style="width:800px; height:450px; background-color: lightgray;" sizing="cover"  preload fade></iron-image>
                <p>{{item.content}}</p>
          </paper-material>
    </template>

Simple right ? but sadly it's throwing below error

XMLHttpRequest cannot load https://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=8&pz=1&cf=all&ned=in&hl=en&topic=tc. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.

I asked the same question in SO but got response from one guy he told me to use byutv-jsonp and that's too having the some issue like only receive [] response not {} response. Finally I'm here for answer...

iron-request swallows/replaces non-200 response body

In the event that a non-200 response is received, the response body is not made available to the caller. Data in the error's response body will often contain information that can help the client inform the user about the nature of an error.

Ajax util object?

I really don't care for this component's predecessor, core-ajax. Inserting an element into the template section of the code is awkward and attribute string limitations suck, I really want parameterized queries.

Why don't you just throw an Ajax utility function into Polymer?

Refuse to make auto request if url is an empty string

I have an annoying behavior of iron-ajax that has bitten me a few times so I'm curious if we could get some discussion about this. Example, if you have an iron-ajax defined as so:

<iron-ajax auto url="[[_urlFor(user)]]"></iron-ajax>

Here, _urlFor(user) is a computed binding. Polymer 1.0 is smart enough to not set this value until user is defined the first time, so if user is null, the iron-ajax element's url property becomes the default empty string. However, the auto mode of the iron-ajax element will make it make a request anyway: to the root of the domain your browser is on.

The problem I'm having is that it auto-requests before binding completes. For example, if I have something roughly like this (even though this syntax is wrong, just understand my-element has a property named userId):

<my-element user-id="zuck">
    <!-- in shadow -->
    <iron-ajax auto url="[[_urlFor(userId)]]"></iron-ajax>
</my-element>

When creating the my-element it creates the iron-ajax which immediately sends a request though its url is empty. Fractions of a second later, back in my-element it finishes creating its DOM and sets up the bindings, this causes iron-ajax to update its url using the computed binding, setting the right URL.

So when the dust settles I have a spurious request that is almost guaranteed to be pointless, followed immediately by the legitimate request that I expect.

A possible fix for this would be simply to make the auto-request require that the url is not an empty string, otherwise not actually make the request. If you did need to hit the root, you would set the url as simply /, which is what most people would do anyway.

What do you think?

params handling of arrays

I was just speaking with someone on Slack about passing arrays into params and after a bit of testing I see that params converts an array to:

arr=1%2C2%2C3

this is the result of:

params: {arr = [1,2,3]}

This is the result of URI encoding the actual array... While there is no standard way to interpret arrays in QueryParams the 2 camps most often seen is that arrays break down into:

?arr=1&arr=2&arr=3

or

?arr[]=1&arr[]=2&arr[]=3

It would seem logical that iron-ajax either used one of these patterns or provide a simple means of overriding the queryString method

Documentation provided is incorrect

In Documentation - API Reference - the example for body is wrong
instead of
<iron-ajax method="POST" auto url="http://somesite.com" body='{"foo":1, "bar":2}'> </iron-ajax>

it should be
<iron-ajax method="POST" auto url="http://somesite.com" body='foo=1&bar=2'> </iron-ajax>

Thanks

Can't access response text for errors

I want to display the server responses for context when errors occur (as I was able to do with core-ajax in v0.5), but the last-error object itself only contains a Polymer-generated string (Error: The request failed with status code: 500) and the last-response object is undefined.

iron-ajax not posting data

From @ahumblenerd on June 20, 2015 15:0

<dom-module id="my-new-app">
<style>
</style>
<template>

  <iron-ajax
      id="ajax"
      handle-as="json"
      content-type="application/json"
      method="POST"
      body={"user":2,"dob":"2015-06-10","jobs":1,"skills":[],"about":"cool"}
      on-response="hresponse"
      debounce-duration="3000">
  </iron-ajax>
  <button on-click="setajax">Click me</button>
</template>
<script>
Polymer({
  is: "my-new-app",
  setajax: function () {

      this.$.ajax.url="http://127.0.0.1:8000/users/";
    this.$.ajax.generateRequest();
  },
  hresponse: function(request) {
    console.log(request.detail.response);
    console.log(this.$.ajax.lastResponse);
    console.log(this.$.ajax.params);
  }
});
</script>
</dom-module>

This does not post data correctly to the server. Also when i put in a console.log inside the iron-ajax.html file i found out that contentType was still set as application/x-www-form-urlencoded . The documentation says we can specifiy contentype by specifiying contentType = {String}.

Copied from original issue: Polymer/polymer#1929

Post methode

Hello together,

I have an issue with the following iron-ajax:

<iron-ajax
                id="ajaxLogin"
                url="www.example.org"
                method="POST"
                on-response="handleResponse"></iron-ajax>

I start the request by

var test = '{ "username" : "testname" }';
                this.$.ajaxLogin.body = test;
                this.$.ajaxLogin.generateRequest();

My PHP-File contains only this:

echo 'POST: ' . $_POST['username'];

But nothing is shown.

Is this a bug?

Thank you!
Lars

iron-ajax accessibility issues

Audit results:
[Severe] Elements with ARIA roles must use a valid, non-abstract ARIA role (1)
[Warning] Text elements should have a reasonable contrast ratio (1)
[Warning] The purpose of each link should be clear from the link text (1)
Not applicable tests (10)
Passing tests (4)

The alt text for the link is "link image watch". It should be something a bit more descriptive about where the user will be taken upon clicking. This is less a concern about the demo page and more that the developer should just be sure to use better labels there.

setting request headers with dynamic values

I am trying send the value of an input field residing within a polymer template as part of a request header, and i was wondering if this is simply not supported...?

I used to do it with setRequestHeader() on an XMLHTTPRequest. Now that I want to refactor using <iron-ajax> I don't find a way to achieve this.

<input id="inputaccesstoken" type="text" value="{{accesstoken::input}}"></input> <iron-ajax id = "doGetToken" url="https://api.pushbullet.com/v2/users/me" handle-as="json" on-response="handleGetToken"> </iron-ajax>
...
<script> Polymer({ is: 'PushBullet-access-token', preventDispose: true, properties: { accesstoken: { type: String }, },
...

I tried
this.$.doGetToken.headers '{"Authorization": "Bearer ' + this.accesstoken + '"}';

and I tried some kind of data-binding
<iron-ajax
...
headers={{getAuthHeader}} </iron-ajax>
where getAuthHeader is a method returning the accesstoken property.

Neither approach worked.

on-error doesn't fire for network errors

I'm trying the following code to send ajax requests:

    <iron-ajax
      id="fetchData"
      url="/foo.php"
      handle-as="json"
      on-response="_fetchDataSuccess"
      on-error="_fetchDataFailure"
      method="POST"
      last-response="{{fetchDataResponse}}"
      debounce-duration="500"
      body=''>
    </iron-ajax>

Which works fine, until I expect _fetchDataFailure to be called. I pull my internet cable and create a request, and _fetchDataSuccess is still called EVEN THOUGH I don't have any internet connection and the message in the console is a clear FAILURE indicating I have no internet.

This behavior is very weird. Looking at the source I can see the issue which I hope can be resolved: https://github.com/PolymerElements/iron-ajax/blob/master/iron-request.html#L120

Any workarounds?

Content-Type/Headers corrupts if FormData is used

<iron-ajax id="ajax1" url="/upload" method="POST" content-type="multipart/form-data"></iron-ajax>
<iron-ajax id="ajax2" url="/upload" method="POST"></iron-ajax>

var fd=new FormData();
fd.append("name","John");
fd.append("where","Here");
this.$.ajax1.body=fd;
this.$.ajax1.generateRequest();

this.$.ajax2.body=fd;
this.$.ajax2.generateRequest();

ajax1: The server receives an invalid multipart/form-data request.

ajax2: All pairs of form key/value are squeezed into one pair of key/value. The server receives something like this:

key:

-------WebKitFormBoundaryqArehja7
Content-Disposition: form-data; name

value:

"name"

John
-------WebKitFormBoundaryqArehja7
Content-Disposition: form-data; name="where"

Here
-------WebKitFormBoundaryqArehja7--

After the following two statements are inserted into line# 323 in function requestHeaders(), the server appears to receive good requests:

if(this.body instanceof FormData)
    delete headers["Content-Type"];

Error response body

Hi,

how can I get the response body for requests that throw an error?
Neither the last-error property nor the parameters given to the on-error function seem to contain a reference to the error body.
I need to be able to forward the error messages over to the user in order to use it productively.

Regards,
Kylex

Doesn't seem to be sending headers for me

In chromium developer tools (Version 43.0.2357.81 Ubuntu 14.04 (64-bit)), I can select the element and do

$0.headers
"{"X-Requested-With": "XMLHttpRequest", "Authorization": "Basic M2Q4NjU0MmItMjA3Ny00ZDNlLThhNjQtMmY5MzU0NTNiMDljOjkxMWMyZDUzLTM1ZjQtNGMyZC04NmNkLWI4OTgyMzZkYzMwMg=="}"

$0.generateRequest()

Then the network view -> xhr shows

Request URL:http://localhost:4000/3%3A4/authcheck
Request Method:GET
Status Code:401 Unauthorized (from ServiceWorker)
Response Headers
access-control-allow-origin:http://localhost:3000
content-length:15
content-type:text/plain; charset=utf-8
date:Thu, 09 Jul 2015 03:03:14 GMT
www-authenticate:Basic realm="Authorization Required"
Request Headers
Provisional headers are shown
Content-Type:application/x-www-form-urlencoded
Referer:http://localhost:3000/?target=3:4&env=development
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.81 Chrome/43.0.2357.81 Safari/537.36

Neither this window nor the chrome://net-internals dump shows the authentication header in the request

And then (unknown if related) there is some kind of infinite loop and crash, I can't seem to figure out how to debug where it is, something about polymer 1.0 is capable of doing some bad things to chromium developer tools.
(for instance I can get it into states where $() doesnt work in the console anymore without reloading the browser)

Iron-ajax is not including custom headers

Hi,

When you pass header to iron-ajax component int this way

//ajax is a reference to <iron-ajax....></iron-ajax>
 ajax.headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'other': 'other_value'
      };

the component is not copying the headers in "requestHeaders" before send the request.
In the method

 get requestHeaders() {
      var headers = Object.create(this.headers || {});

      if (!('content-type' in headers)) {
        headers['content-type'] = this.contentType;
      }

      return headers;
    },

"headers" is an object with the propterties you passed included in its prototype. So , by exmaple, the checking

  if (!('content-type' in headers)) {

always comes in the block and the passed headers will never be sent later in the request

on-response not defined in documentation

In example:

<iron-ajax
    auto
    url="http://gdata.youtube.com/feeds/api/videos/"
    params='{"alt":"json", "q":"chrome"}'
    handle-as="json"
    on-response="handleResponse"
    debounce-duration="300"></iron-ajax>

on-response is declared, but it is not in any of the documentation Properties.

contentType property is not setting the Content-Type Header

When setting contentType property - as indicated in the docs - for instance, like this:

<iron-ajax
      ...
      contentType="application/json"
      ...>
</iron-ajax>

iron-ajax is not working properly since it doesn't establish the Content-Type header in the XMLHttpRequests object - which belongs to iron-request. As a workaround, using header property instead contentType property, it just works.

<iron-ajax
      ...
      headers='{"Content-Type": "application/json"}'
      ...>
</iron-ajax>

Handling of 401 Unauthorized by XMLHttpRequest instead of user agent

Right now when specifying Authorization headers, upon the request returning a 401 status code the user agent will handle the request by asking for credentials (modal).
However, one might want to be able to handle this response through the iron-ajax response callback function.
To solve this the xhr.open() function has to be modified according to the following w3c spec:

If the user agent supports HTTP Authentication and Authorization is not in the list of author request headers, it should consider requests originating from the XMLHttpRequest object to be part of the protection space that includes the accessed URIs and send Authorization headers and handle 401 Unauthorized requests appropriately.

If authentication fails, Authorization is not in the list of author request headers, request username is null, and request password is null, user agents should prompt the end user for their username and password.

If authentication fails, Authorization is not in the list of author request headers, request username is non-null, and request password is non-null, user agents must not prompt the end user for their username and password. [RFC2617]

End users are not prompted if username/password are provided through the open() API so that authors can implement their own user interface.

See: http://www.w3.org/TR/XMLHttpRequest1/
and
http://www.w3.org/TR/XMLHttpRequest1/#dom-xmlhttprequest-open

The solution for this would be to add the ability to specify the username and password as parameters in the xhr.open() function.
e.g.

xhr.open(
    options.method || 'GET',
    options.url,
    options.async !== false,
    options.username,
    options.password
);

Of course a check will have to be made whether or not the username and password are actually provided. I will leave that implementation up to you.

handle-as:'xml' results in warning from xhr.responseType

When setting handle-as: 'xml', the response is correctly identified as XML but the xhr.responseType expects 'text' instead of 'xml' at 203:

xhr.responseType = xhr._responseType = (options.handleAs || 'text');

This results in the warning:

The provided value 'xml' is not a valid enum value of interface XMLHttpRequestResponseType.

POST base64 encoded image to Endpoints API

I have problems uploading very big strings (base64 encoded images) with iron-ajax.

<iron-ajax id="post"
  url="https://undergogos.appspot.com/_ah/api/undergogo/v1/image"
  on-response="postResponded"
  handleAs="json"
  method="POST"
  last-response="{{postResponse}}"
></iron-ajax>

postGo:function(img64){

      this.$.post.body= '{"img":' + img64 + '}';
      this.$.post.generateRequest();

},

The above results in 400 parse error on an Endpoints API as it is an String not an Object. Uploading it with the params attribute works fine as long the images are very small (<10KB). With bigger images, Chrome fires net::ERR_CONNECTION_CLOSED

Changing the body attribute in iron-ajax to an Array and passing form data works:

iron-ajax:

body: {
    type: Array,
    value: function() {
      return [];
    }
  }

request:

var formData = new FormData();
formData.append("img", img64);

this.$.post.body= formData;
this.$.post.generateRequest();

It also works when doing an iron-request instead of an iron-ajax-request as the body attribute of iron-request supports (ArrayBuffer|ArrayBufferView|Blob|Document|FormData|null|string|undefined). Why doesn't iron-ajax support that data types?

Loading attribute not functioning

While using iron-ajax I am unable to use the loading attribute as described in the docs.

Upon closer inspection I don't see anything in iron-ajax.html that even touches the loading property. Has this been implemented and I'm being foolish or is this missing?

Connection errors (net::ERR_CONNECTION_REFUSED) trigger the on-response handler instead of on-error

If <iron-ajax> makes a request and can't connect to the server (e.g. the webserver is down) it triggers the on-response handler.
I expect it to trigger the on-error handler and set lastError, as it does e.g. for a 404 response.

Possibly related to #19 and #17.

For clarity, below is a complete example (my-elem.html and index.html) and the steps I'm taking.

  • Start a webserver, e.g. python3 -m http.server
  • Open http://localhost:8000
  • Stop the webserver
  • Clicking the first button does <iron-ajax>.generateRequest() โ†’ the on-response handler runs and prints ev.detail.response null, ev.detail.xhr.status 0. Afterwards, the xhr.addEventListener('error', โ€ฆ) handler runs (at
    this.rejectCompletes(error);
    ). But my on-error handler doesn't run and lastError is not set.
  • Clicking the second button makes a plain XMLHttpRequest which correctly handles this net::ERR_CONNECTION_REFUSED case by running its onerror handler.
  • my-elem.html
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/iron-ajax/iron-ajax.html">

<dom-module id="my-elem">
  <template>
    <iron-ajax id="ajax" url="/dummy"
      on-response="handleResp"
      on-error="handleErr"></iron-ajax>
    <button on-click="useIronAjax">Iron-Ajax</button>
    <button on-click="useXHR">XmlHttpRequest</button>
  </template>
</dom-module>

<script>
Polymer({
  is: 'my-elem',

  handleResp: function(ev) {
    console.log('Response', ev.detail.response, 'status', ev.detail.xhr.status);
  },

  handleErr: function(ev) {
    console.log('Error');
  },

  useIronAjax: function() {
    this.$.ajax.generateRequest();
  },

  useXHR: function() {
    var xhr = new XMLHttpRequest();
    xhr.onerror = function() {
      console.log('XHR error');
    }
    xhr.open('GET', '/dummy', true);
    xhr.send();
  }
});
</script>
  • index.html
<!DOCTYPE html>
<html>
  <head>
    <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
    <link rel="import" href="my-elem.html">
  </head>
  <body>
    <my-elem></my-elem>
  </body>
</html>

Empty body response results in missing property "lastResponse"

Request URL:http://localhost:4000/13%3A6/requestauth
Request Method:POST
Status Code:200 OK (from ServiceWorker)
Response Headers
access-control-allow-credentials:true
access-control-allow-headers:Authorization, Origin
access-control-allow-methods:POST, GET, OPTIONS
access-control-allow-origin:http://localhost:3000
content-length:0
content-type:application/json; charset=utf-8
date:Sat, 11 Jul 2015 21:02:05 GMT
Request Headers
Provisional headers are shown
Authorization:Basic MWI3NWQxODQtZGJkMi00MGJlLTk5OGEtYzc2ZmRiY2NmYTExOjA4MzRlOTFlLTM4NWMtNDMzMS04MzUwLWY0ODhlYTM1MTBiMw==
Content-Type:application/x-www-form-urlencoded
Origin:http://localhost:3000
Referer:http://localhost:3000/?target=13:6&env=development
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36

A purposefully empty body, with a 200 response code, and content-type: json results in the

this.$.ajaxid.lastResponse = null

Is there a reason this property doesn't exist instead of being an empty object?

Reminds of the days when I had to null check every single thing I was referencing in Java.

allow content type to be calculated by user agent making the request

Hello,

Can we please allow the content type to be omitted & calculated by the browser/user agent in some cases ? Removing Content-Type does not seem to be supported.

An example where this may be useful is when the content-type attribute is specified as multipart/form-data.

This was handling pretty well by core-ajax not sure why this was changed when it was ironized!

Thanks

@jongeho1

POST with params is treated as GET by PHP

Hi,
I'm not sure if this would be considered a bug, or merely an unfortunate design decision, but, iron-ajax is a pain to use with POST requests with PHP.

Sending a POST request with data params to my PHP page results in params added to queryString, but not POST body. Despite the fact that request headers' method is correctly set to POST, PHP interprets query string params as $_GET, and $_POST is empty.

Iron-ajax does not provide a way to convert an object to query string via a simple interface, and I have to do this gymnastics for each request:

var queryParts = [];
for (param in myParams) {

    var value = myParams[ param ];
    var param = window.encodeURIComponent( param );

    if ( value !== null ) {
        param += '=' + window.encodeURIComponent( value );
    }
    queryParts.push(param);
}
ajax.method = 'POST';
ajax.body = queryParts.join('&');
ajax.generateRequest();

I believe it would be better if this was handled this way by default, internally.

When this.body is an object we should encode it before sending it up.

Hi,

I am trying to make a login component using iron-ajax.
I manage to get my component working but I got one problem.

Here's my code :

_user matches the type {username: string, password: string}.

<login-form
  credentials="{{_user}}"
  on-login="handleLogin">
</login-form>

<iron-ajax
  id="ajax"
  url="http://localhost:3000/user"
  method="POST"
  content-type="application/json"
  last-response="{{_response}}">
</iron-ajax>
handleLogin: function() {
  this.$.ajax.body = JSON.stringify(this._user);
  this.$.ajax.generateRequest();
}

This is working fine. But I am uncomfortable with the this.$.ajax.body = JSON.stringify(this._user); line.

I can't get it working by passing body="[[_user]]" to the iron-ajax component.
This example is not working because iron-ajax send [object Object] in the POST request body. The json object passed with body attribute isn't stringified.

<login-form
  credentials="{{_user}}"
  on-login="handleLogin">
</login-form>

<iron-ajax
  id="ajax"
  url="http://localhost:3000/user"
  method="POST"
  content-type="application/json"
  body="[[_user]]"
  last-response="{{_response}}">
</iron-ajax>
handleLogin: function() {
  this.$.ajax.generateRequest();
}

Is the the expected behavior ? If not is it possible to stringify the body if its type is Object ?

Thanks in advance,
Thomas

suggest iron-ajax should support only one inflight request

IMO, iron-ajax should service only one request per instance. If a new request is made before an earlier one has completed, the earlier request should be orphaned and only the new request should be serviced.

Applications that need to make multiple parallel requests would do this with a repeat or imperatively (or conceivably with some sort of iron-multi-ajax element).

Connection Error handling

This is a request to handle connection issues better in core-ajax connection issues returned a response of 0 might be better to return the actual error i.e. net::ERR_NAME_NOT_RESOLVED

Response not sending full XHR object

Hi, There are already two issues that talk about the error handling not managing xhr.status and assume that all response is of value 200. In the old core-xhr.html it sends the full line 68 "return xhr;" in iron-request sends the xhr.response-. Are there any plans to send the full xhr object as some projects may be performing on handling based on the status or header ? Might might be useful to have the default in the line 232 of iron-request.html that currently return the xhr.responseText to return xhr instead. For the json object maybe something like { status:200, header:"???", response:"???"}.

Bind not work

I made a simple request json in iron-ajax, like:

            <paper-material elevation="1" style="min-width:400px">
                <template is="dom-bind">
                    <h1>Test2</h1>
                    <iron-ajax 
                        auto
                        url="/test.json" 
                        handle-as="json"
                        last-reponse="{{datalist}}"
                        ></iron-ajax>
                    <template is="dom-repeat" repeat="[[datalist]]">
                        <p>[[item.name]]</p>
                    </template>
                </template>
            </paper-material>

in network show the list retrieve but the datalist is not populated.

my bower.json
...
"dependencies": {
"paper-elements": "PolymerElements/paper-elements#latest",
"iron-ajax": "PolymerElements/iron-ajax#~1.0.2"
}
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.