Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

How can I know the json has been loaded #176

Closed
Mabbs opened this issue Jul 22, 2021 · 4 comments
Closed

How can I know the json has been loaded #176

Mabbs opened this issue Jul 22, 2021 · 4 comments

Comments

@Mabbs
Copy link

Mabbs commented Jul 22, 2021

---
layout: default
title: 搜索
---

<h1>搜索</h1>
<!-- HTML elements for search -->
Keyword: <input type="text" id="search-input" placeholder="Search blog posts.."><br>
<ul id="results-container"></ul>

<!-- or without installing anything -->
<script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
<script>
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
var mykeyword = GetQueryString("keyword");
var sbox = document.getElementById('search-input');
var status = false;
if(mykeyword !=null && mykeyword.toString().length>1){
     sbox.value = mykeyword;
}
var sjs = SimpleJekyllSearch({
     searchInput: sbox,
     resultsContainer: document.getElementById('results-container'),
     json: 'search.json',
     searchResultTemplate: '<li>{date} - <a href="{{ site.url }}{url}">{title}</a></li><br>',
});
sjs.search(mykeyword)
</script>

Firstly, this is my code, I tried use search function, It can use while I input to console: sjs.search(mykeyword), but this code in script, json may not be load. so how can I know the json has been loaded?

@Mabbs
Copy link
Author

Mabbs commented Jul 22, 2021

I solved the problem:

$(window).bind("load", function () {
     sjs.search(mykeyword);
})

@Mabbs Mabbs closed this as completed Jul 22, 2021
@Mabbs
Copy link
Author

Mabbs commented Jul 22, 2021

I solved the problem:

$(window).bind("load", function () {
     sjs.search(mykeyword);
})

Hallucination

@Mabbs Mabbs reopened this Jul 22, 2021
@Funeoz
Copy link

Funeoz commented Jul 25, 2021

You can see your json file in the network tab of your browser's devtools.

@Mabbs
Copy link
Author

Mabbs commented Jul 25, 2021

You can see your json file in the network tab of your browser's devtools.

I mean program how to know,the success function is fake,i can't use callback.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants