2014-09-22 96 views
0

我一直在爲此工作好幾天,沒有什麼比這更好的了!我有一個應用程序使用cookie進行會話處理。該應用程序使用我在標題中導入的多個自定義元素,其中一些需要使用來自cookie session的信息進行ajax-core調用。問題在於cookie未設置(情況:首次啓動),因此,我登錄到應用程序,並且必須重新加載頁面才能開始獲得'core-ajax auto'結果。我不知道如何做一個監聽器或如何重新加載所有的自定義元素或如何重新加載特定的核心ajax調用。重新加載自定義元素的聚合物元素或ajax調用

你們有些人有類似的情況?這是解決它的最佳方法?

在此先感謝!

回答

0

我有同樣的想法,但如果用戶沒有登錄一段時間,它會在一個不希望的循環(我認爲,也許我錯了),所以,我最終做了什麼?

我有我的Ajax調用,並在響應行動我將文件導入頭與一個啞巴功能

if(data.user){ 
    this.importLinks(); 
} else { 
..... 
} 


importLinks: function() { 
    this.createLinkRel('/static/resources/custom-elements/file.html'); 
    this.createLinkRel('/static/resources/custom-elements/log.html'); 
    this.createLinkRel('/static/resources/custom-elements/us.html'); 
    this.createLinkRel('/static/resources/custom-elements/shop.html'); 
}, 


createLinkRel: function (href){ 
    var script = document.createElement('link'); 
    script.rel = 'import'; 
    script.href = href; 
    document.getElementsByTagName('head')[0].appendChild(script); 
} 

感謝你的時間來閱讀我的文章和答案!

2

這聽起來好像你需要設置core-ajax auto =「false」並延遲查詢setTimeout();

您可以通過爲聚合物元素指定一個id(即本示例中的ajax)並調用go()來調用聚合物元素中的ajax調用;函數

this.$.ajax.go(); 

要從元素外部調用它,必須首先在元素內部生成函數。

Polymer('custom-element', { 
    doSend: function (event, detail, sender) { 
    this.$.ajax.go(); 
    } 
}); 

然後調用,從你的主js文件與

document.querySelector('custom-element').doSend(); 

所以把所有的一起,延緩查詢,你可以使用

setTimeout(function() { 
    document.querySelector('custom-element').doSend(); 
}, 1000); 

稱之爲核心的去功能在等待1秒後自定義元素內部的ajax。

+0

這並沒有完全解決我的問題,但它導致我在幾個小時和幾個小時沒有進展後走上了正確的軌道。謝謝! – 2015-03-13 16:18:47