2013-08-08 2 views
1

typeahead.js에서 프리 페치 옵션을 사용할 수 없습니다. 로컬 데이터가 정상적으로 작동합니다. 이전에 게시 된 질문에 대한 답변은 캐싱이 문제가 될 수 있음을 암시하지만, ttl을 0으로 설정했으며 Firefox 및 Chrome의 개인 정보 보호 브라우징 모드에서 테스트 중입니다. 내가 뭘 놓치고 있니? JS 작업을 할 때Typeahead.js 프리 페치 옵션이 작동하지 않습니다.

<!DOCTYPE html> 
<html> 
<head> 
    <link rel="stylesheet" type="text/css" href="http://twitter.github.com/typeahead.js/releases/latest/typeahead.css"> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="http://twitter.github.com/typeahead.js/releases/latest/typeahead.js"></script> 
</head> 

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('#searchText').typeahead([ 
    { 
     name: 'terms', 
     //local: ["United States", "Canada"], 
     prefetch: 'http://twitter.github.io/typeahead.js/data/countries.json', 
     ttl: 0 
     } 
    ]); 
    }); 
</script> 

<body> 
<div class="container"> 
    <input class="typeahead" type="text" id="searchText"> 
</div> 
</body> 

</html> 
+0

@ PauloTomé 그런 식으로 백틱을 사용하지 마십시오. 강조 표시가 아닙니다. –

답변

1

당신은 항상 console (방화범/크롬 개발 도구)를 확인해야 뭔가 "작동하지 않는", 그것은 당신의 가장 친한 친구입니다.

이 경우 prefetch이 작동하지 않는 것은 아닙니다. 그러나 Github은 다른 도메인에서 json을 가져올 수 없습니다. 로컬 작업이 예제를 얻으려면, 당신이 JSON 파일을 다운로드해야하고 같은 URL을 약간 수정 한 다음, 로컬로 설정 그래서

XMLHttpRequest cannot load http://twitter.github.io/typeahead.js/data/countries.json. Origin http://yourdomain is not allowed by Access-Control-Allow-Origin. 

: 당신이 당신의 콘솔을 선택하면이 오류가 발생합니다 :

$(document).ready(function(){ 
    $('#searchText').typeahead({ 
     name: 'terms', 
     prefetch: '/data/countries.json', // go to http//yourdomain/data/countries to make sure the path is correct 
     ttl: 0 
    }); 
}); 

희망이 있습니다.

+0

그게 도움이됩니다, 고마워요. 어떤 이유로 든 Firebug의 콘솔 섹션에 오류 메시지가 표시되지 않지만 Chrome으로 전환하면 해당 메시지가 표시됩니다. 도와 줘서 고마워. – user2664728