0

I've been trying to get json data from the GW2 server, which didn't work with iron-ajax due to cross-domain issues. Than I tried this byutv-jsonp and that worked.

The problem now is that I get a response with the right data, but it's not triggering the on-response handler. So the data is never put inside the variable :/

Anyone has a tip, hint or clue?!

Source of byutv http://coderfin.github.io/byutv-jsonp/components/byutv-jsonp/

<dom-module id="about-pagina">
 <template>
 <style include="shared-styles">
 :host {
 display: block;
 }
 </style>

 <h1>about-pagina</h1>
 <vaadin-grid id="grid" items="[[_c_studenten]]" selected-items="{{selected}}">
       <vaadin-grid-column>
         <template class="header">Account Name</template>
         <template>
           <div class="capitalized">[[item.name]]</div>
         </template>
       </vaadin-grid-column>

       <vaadin-grid-column>
         <template class="header">Rank</template>
         <template>
           <div class="capitalized">[[item.rank]]</div>
         </template>
       </vaadin-grid-column>

       <vaadin-grid-column>
         <template class="header">Date Joined</template>
         <template>
           <div class="capitalized">[[item.joined]]</div>
         </template>
       </vaadin-grid-column>

       <vaadin-grid-column>
         <template class="header">Docent</template>
         <template>
           <div class="capitalized">[[item.docent]]</div>
         </template>
       </vaadin-grid-column>
       <vaadin-grid-column>
         <template class="header">Lokaal</template>
         <template>
           <div class="capitalized">[[item.locatie]]</div>
         </template>
       </vaadin-grid-column>
         <vaadin-grid-column>
           <template class="header">Klas</template>
           <template>
             <div class="capitalized">[[item.klas]]</div>
           </template>
         </vaadin-grid-column>
       </vaadin-grid-column>
     </vaadin-grid>
     <paper-button on-tap="derp" raised>Annuleren</paper-button>

 <byutv-jsonp
   id="ajax_members_get"
   method="GET"
   url="https://api.guildwars2.com/v2/guild/secretcode/members"
   params='{"access_token":"secretcode"}'
   handle-as="json"
   last-response="{{_c_studenten}}"
   on-response="_members_get_response_handler">
 </byutv-jsonp>

 </template>
 <script>
 Polymer({
 is: 'about-pagina',
 properties: {
   c_visible: {
     type: Boolean,                                      /* true when element is the active visible item */
     value: false,
     observer: '_initializing',
   },
   _c_studenten: {
     type: Array,
   },
 },
 _initializing : function() {
   if (this.c_visible) {
      console.log("about-pagina");
      this._members_get_request_handler();
   }
 },
 _members_get_request_handler: function() {
   console.log("_members_get_request_handler");
   this.$.ajax_members_get.contentType="application/json";
   this.$.ajax_members_get.body={
   };
   this.$.ajax_members_get.generateRequest();
 },

 _members_get_response_handler: function(request) {
   console.log("_members_get_response_handler aantal studenten="+request.detail.response.length);
   this._c_studenten = request.detail.response;
 },
 derp: function(){
   console.log([[_c_studenten]]);
 }
 });
 </script>
</dom-module>
Edo
  • 85
  • 8
  • Can you post all code from your element in which you send this request? Your functions must be in ` – Dmytro May 07 '17 at 09:43
  • I've added all the code after your request, all imports are done as they should've in another import file. – Edo May 07 '17 at 17:42
  • If l understand you correct your request was sended by function `_members_get_request_handler` to server and you receive some data in response and can see them on Network tab in Chrome dev tools but your listener `_members_get_response_handler` doesn't fired, right? If it is you can try to set event handler without underscore in begining like this `members_get_response_handler` cause l had some problems with it – Dmytro May 07 '17 at 19:43
  • I've changed the function and caller to members_get_response_handler but no change :/ And yes you understood correctly – Edo May 07 '17 at 20:00
  • Several years ago GW2 said they would not support JSONP (https://forum-en.guildwars2.com/forum/community/api/HTTP-access/first#post2064091). Without JSONP support byutv-jsonp will not work. – coderfin Sep 15 '17 at 16:31

1 Answers1

0

As you are specifying _c_studenten's value in _members_get_response_handler function, you can remove last-response="{{_c_studenten}}" from the iron-ajax. That prevents setting the value twice. Now you can make sure that your data is in Array and not as Object (vaadin-grid requires array data). That probably does the trick. If not, make sure the format of data that iron-ajax fetches.

samiheikki
  • 99
  • 8