2016-05-08 3 views
0

In den Firefox-Entwickler-Tools I die folgende Protokoll Ausgabe:Eisen-Ajax im Tandem mit Polymer-Starter-Kit Fehlverhalten oder so etwas. Es sendet Anfragen an eine andere URL als die ich erwarte

GET XHR http://localhost:8080/localhost:8080/journal_tag 

obwohl ich gehen wollen:

http://localhost:8080/journal_tag 

I versuchen Sie, den Serverstandort zu binden, von dem die xhr-Antwort auf die Variable 'this.the_server_url' kommen soll. Aber ich bin ratlos, denn wenn ich entweder tun von

console.log(document.location.protocol+document.location.host+"/journal_tag") 
console.log(this.the_server_url) 

I

bekommen
"http:localhost:8080/journal_tag" 

das ist, wo Server-Seite gehen Code auf die xhr Anfrage reagieren soll. Das Protokoll der Firefox-Entwickler-Tools sagt mir, dass Iron-Ajax oder Iron-Ajax in Verbindung mit page.js vom Polymer-Starter-Kit sich schlecht benimmt, obwohl es das richtige xhr-Ziel in der Variable "the_server_url" hat. Wenn jemand irgendwelche Gedanken dazu hat, würde ich eine Antwort schätzen.

Das ist mein js Code:

<dom-module id="journal-tag"> 
    <template> 
    <paper-input value={{the_new_tag}}> 
     Enter the new tag 
    </paper-input> 
    <paper-button raised on-tap="tap_new_tag"> 
     Submit tag 
    </paper-button> 
    <iron-ajax 
     auto 
     url={{the_server_url}} 
     params={{ajax_new_tag}} 
     handle-as="json" 
     on-response="new_tag_response" 
     last-response={{the_xhr_response}} 
     debounce-duration="300"> 
    </iron-ajax> 
    </template> 
    <script> 
    (function() { 
    'use strict'; 

    Polymer({ 
     is: 'journal-tag', 
     properties:{ 
      the_new_tag:{ 
       type:String, 
       notify:true 
      }, 
      the_server_url:{ 
       type:String, 
       notify:true 
      }, 
      ajax_new_tag:{ 
       type:String, 
       notify:true 
      }, 
      the_xhr_response:{ 
       type:String, 
       notify:true 
      } 
     }, 
     ready : function(){ 
      this.the_server_url=document.location.protocol+document.location.host+"/journal_tag"; 
     }, 
     tap_new_tag : function(){ 
//parameter format for{{ajax_new_tag}}: 
//'{"alt":"json", "q":"chrome"}' 
//   this.the_new_tag="tadu"; 
      this.ajax_new_tag={"tag" : this.the_new_tag}; 
     }, 
     new_tag_response : function(){ 
      console.log("tada") 
      console.log(this.the_xhr_response) 
      alert(this.the_xhr_response) 
     } 
    }); 
    })(); 
    </script> 
</dom-module> 

Hier ist meine Server-Seite gehen Code, aber es scheint es nie aufgerufen wird:

... 
http.HandleFunc("/journal_tag",journal_tag) 
... 
func journal_tag(w http.ResponseWriter, r *http.Request){ 
    c := appengine.NewContext(r) 
    u := user.Current(c) 
    if u == nil { 
     io.WriteString(w, "strange_matter") 
     return 
    } 
// var tag=r.FormValue("tag") 
// io.WriteString(w, "{\"tag\":\"" + tag + "\"}") 
    io.WriteString(w, "{\"tag\":\"tada\"}") 
} 

Antwort

0

Scheint, wie

document.location.protocol+ 
"//"+ 
document.location.host+ 
"/journal_tag" 

behebt alles tun.

1

Ein paar Dinge. Sie fehlen die Schrägstriche in http:localhost:8080/journal_tag Es sollte http://localhost:8080/journal_tag sein. Sie können auch die Entwicklertools für den Browser verwenden, in dem Sie sich befinden, um alle von Ihnen gesendeten XHR-Anforderungen anzuzeigen. Überprüfen Sie dort, was die gesendeten Anforderungsheader sind.

+0

Thx für die Antwort. – branco

Verwandte Themen