미디어위키 검색창 기능 구현

Jmnote (토론 | 기여)님의 2016년 11월 1일 (화) 00:50 판 (새 문서: ==개요== ;미디어위키 검색창 기능 구현 <source lang='html'> <input id="searchterm" type="text" /> <button id="search">search</button> <ul id="results"></ul> <script> $(...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요

미디어위키 검색창 기능 구현
<input id="searchterm" type="text" />
<button id="search">search</button>
<ul id="results"></ul>

<script>
$("#searchterm").keyup(function (e) {
    var q = $("#searchterm").val();
    $.getJSON("http://en.wikipedia.org/w/api.php?callback=?", {
        srsearch: q,
        action: "query",
        list: "search",
        format: "json"
    },

    function (data) {
        $("#results").empty();
        $("#results").append("Results for: " + q + "");
        $.each(data.query.search, function (i, item) {
            $("#results").append("<li><a href='http://en.wikipedia.org/wiki/" + encodeURIComponent(item.title) + "'>" + item.title + "</a><br>" + item.snippet + "</li>");
        });
    });
});
</script>
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}