2016-05-08 5 views
0

を期待していたものとは異なるURLにリクエストを送信します。iron-ajaxとポリマースターターキットのミスビバブなどが並んでいます。それは私が、私は次のログ出力を取得し、Firefoxの開発者向けツールで

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

私はに行きたいにもかかわらず:

http://localhost:8080/journal_tag 

I xhr応答が来るはずのサーバーの場所をデータ 'this.the_server_url'にバインドしてみてください。私は

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

のいずれかを実行したときに、私は、サーバー側に行くコードはXHRリクエストに応答すべきところである

"http:localhost:8080/journal_tag" 

を取得するので、しかし、私は困惑しています。 Firefoxの開発者ツールのログによると、the_server_url変数に適切なxhrの宛先があるにもかかわらず、iron-ajaxまたはiron-ajaxがpolymer-starter-kitのpage.jsと一緒に誤って動作していることがわかります。誰かがこれに関する考えを持っているなら、私は答えを感謝します。

これは私のJSコードである:ここで

<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> 

は私のサーバーサイド・ゴーコードですが、それが呼ばれることは決してありませんようだ:

... 
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\"}") 
} 

答えて

0

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

修正のすべてをやっように思えます。

1

物事のカップル。 http:localhost:8080/journal_tagにスラッシュがありません。http://localhost:8080/journal_tagにする必要があります。また、ブラウザのDeveloperツールを使用して、送信しているすべてのXHR要求を表示することもできます。リクエストヘッダーの送信内容を確認します。

+0

答えのためのThx。 – branco

関連する問題