2013-07-19 37 views
2

這裏是我的js代碼執行的預輸入:Typeahead.js麻煩 - 建議不會出現

jQuery.noConflict(); 
jQuery(document).ready(function(){ 
    jQuery('.search-field.input').typeahead({ 
     name: 'group-static', 
     prefetch: 'http://ws.luyencong.net/data/search/query.php?do=advanced', 
     header: '<span class="group-title">General Content</span>', 
     template: [ 
     '<img class="icon" src="{{icon}}" style="width: 38px; height: 38px" />', 
     '<div class="icon-desc"><span xmlns="http://www.w3.org/1999/xhtml" class="title">{{name}}</span>', 
     '<span xmlns="http://www.w3.org/1999/xhtml" class="desc">{{description}}</span></div>', 
     '<span class="clear"></span>' 
     ].join(''), 
     engine: Hogan 
    }); 
}); 

的預輸入,執行(因爲我能看到TT-提示輸入,並建議div的包裝) 但是一個麻煩,當我鍵入一個字符,建議不會顯示,因爲它必須是。

我的JSON位於:http://ws.luyencong.net/data/search/query.php?do=advanced

請給我一些幫助。謝謝。

+0

你在JavaScript控制檯中看到任何錯誤? – jharding

+0

不,JSON文件通常是'GET'(但idk爲什麼是紅色,但是當我過濾時它不是錯誤)您可以檢查http://www.luyencong.net – LCTG

+0

你是什麼意思,當你「過濾通過」?看起來問題是由於您提出了跨域請求。如果可能的話,從'luyencong.net'服務JSON,而不是'ws.luyencong.net'。 – jharding

回答

1

這不是一個真正的typeahead.js問題。問題是您正在從luyencong.netws.luyencong.net發出跨域請求。如果可以的話,在luyencong.net上託管prefetch JSON文件 - 這可能是最簡單的解決方案。

jQuery('.search-field.input').typeahead({ 
    // ... 
    prefetch: 'http://luyencong.net/data/search/query.php?do=advanced' 
    // ... 
}); 

如果你不能做到這一點,還有一些其他的選擇: