Skip to content

Instantly share code, notes, and snippets.

@rruhlen
Created September 16, 2013 22:23
Show Gist options
  • Save rruhlen/6587403 to your computer and use it in GitHub Desktop.
Save rruhlen/6587403 to your computer and use it in GitHub Desktop.
you can show suggested articles based on the subject you enter by sending an AJAX request to https://site.desk.com/customer/portal/articles/autocomplete?term=SUBJECT. This request returns a json formatted array of possible articles. We run through that result set and create a link to those articles in the list.
// run as soon as we have input in the subject field
$(‘#subject_input’).on(‘keyup’, function() {
// get the subject
var term = $(this).val();
// run the request – make sure to url encode the subject
$.getJSON(‘https://site.desk.com/customer/portal/articles/autocomplete?term=’ + encodeURIComponent(term), function(response) {
// empty the previous list
$(‘#thelist’).empty();
// for each article returned from the request
$.each(response, function(index, article) {
// add the article to the list
$(‘#thelist’).append(‘<li>’ + article.id + ‘“>’ + article.label + ‘</a></li>’);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment