Polymer / polymer

Our original Web Component library.
https://polymer-library.polymer-project.org/
BSD 3-Clause "New" or "Revised" License
22.04k stars 2.01k forks source link

iron-ajax doesn't work when it is used in a custom element #2194

Closed boloson closed 9 years ago

boloson commented 9 years ago

Hi, I tried to use iron-ajax inside a custom element using the polymer-starter-kit. The ajax request cannot be made with "auto" or the generateRequest() method. However, it works when I import the iron-ajax.html AGAIN in the main index.html.

Here is my code if it helps

<link import="../../bower_components/iron-ajax/iron-ajax.html">
<link import="../../bower_components/iron-input/iron-input.html">
<link import="../../bower_components/paper-button/paper-button.html">
<link import="../../bower_components/polymer/polymer.html">

<dom-module id="my-element">
  <template>
    <p>Hello Mass calculator</p>

    <label>Molecular Formula: </label>
    <input is="iron-input" bind-value="{{bindValue}}" value="{{mf::input}}">
    <paper-button raised class="colorful" on-click="handleClick">Calculate</paper-button>
    <div id="change">need to be change</div>
    <iron-ajax auto id="myajax"
    url= "http://www.chemcalc.org/service"
    params='{"mf": "C1H3", "isotopomers": "jcamp,xy"}'
    handle-as="json"
    on-response="handleResponse"
    debounce-duration="300"></iron-ajax>
  </template>
  <script>
    Polymer({
      is: 'my-element',
      created: function(){
      },

      handleClick: function(){
        //this.myurl = "http://www.chemcalc.org/service";
        this.$.myajax.generateRequest();
        //this.$.myajax
        //console.log(result);
      },

      handleResponse: function(request){
        var myResponse = request.detail.response;
        console.log(myResponse);
      }

    });
  </script>
</dom-module>
boloson commented 9 years ago

UPDATE: It works by changing the import code to <link rel="import" href="...." rather than <link import="..."

kevinpschaaf commented 9 years ago

Great, you've got the correct syntax now. Closing.