Created
July 15, 2018 10:07
-
-
Save alegut/b520b4f2139a409d28e1615c9ed2ed47 to your computer and use it in GitHub Desktop.
Asynchtonous JSON request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getResults() { | |
| $.when( | |
| $.getJSON(universityData.root_url + '/wp-json/wp/v2/posts?search=' + this.searchField.val()), | |
| $.getJSON(universityData.root_url + '/wp-json/wp/v2/pages?search=' + this.searchField.val()) | |
| ).then((posts, pages) => { | |
| var combinedResults = posts[0].concat(pages[0]); | |
| this.resultsDiv.html(` | |
| <h2 class="search-overlay__section-title">General Information</h2> | |
| ${combinedResults.length ? '<ul class="link-list min-list">' : '<p>No general information matches that search.</p>'} | |
| ${combinedResults.map(item => `<li><a href="${item.link}">${item.title.rendered}</a></li>`).join('')} | |
| ${combinedResults.length ? '</ul>' : ''} | |
| `); | |
| this.isSpinnerVisible = false; | |
| }, () => { | |
| this.resultsDiv.html('<p>Unexpected error; please try again.</p>'); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment