Polymer iron-ajax called many times in loop

When I run the page, in the console you can see what many calls to iron-ajax do, I do not know why, please help:

<iron-ajax
  auto id="GetDatUsr"
  url="http://myserver/servweb/all_repusr.php"
  handle-as="json"
  on-response="menuxuser"
  last-response="{{userdata}}"
  debounce-duration="300">
</iron-ajax>

And the function is:

menuxuser: function(){
      var email1 = this.emailData();          
      this.$.GetDatUsr.params = { email: email1};
      this.roll1 = this.$.GetDatUsr.lastResponse;
      var count = Object.keys(this.$.GetDatUsr.lastResponse).length;

      var roll3 = 0;
      for (var i = 0; i < count; i += 1) {
        roll3 = this.roll1[i]["roll"];
      }          
      this.hideMenu(roll3);
    }

The calculation is correct, but it continues to run infinitely.

Upvotes: 0

Views: 216

Answers (1)

Cappittall
Cappittall

Reputation: 3441

Remove auto as at document says ;

auto: boolean = false
If true, automatically performs an Ajax request when either url or params changes

so, iron-ajax fires every time when params is changed. Instead you need to fire iron-ajax manually when you needed:

this.$.GetDatUsr.generateRequest();

Upvotes: 1

Related Questions