1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-14 00:46:38 -05:00
shimapan/assets/js/livesearch.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-08-14 10:21:53 -04:00
function createRequestObject() {
var request_o;
var browser = navigator.appName;
if (browser == 'Microsoft Internet Explorer') {
request_o = new ActiveXObject('Microsoft.XMLHTTP');
}else {
request_o = new XMLHttpRequest();
}
return request_o;
}
var http = createRequestObject();
function liveSearch()
{
var url = '../includes/api.php?do=search';
var s = document.getElementById('qsearch').value;
var params = '&s=' + s;
http.open('POST', url, true);
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.setRequestHeader('Content-length', params.length);
http.setRequestHeader('Connection', 'close');
http.onreadystatechange = function () {
if (http.readyState == 4 && http.status != 200) {
document.getElementById('searchResults').innerHTML = '<li>Loading...</li>';
}
if (http.readyState == 4 && http.status == 200) {
document.getElementById('searchResults').innerHTML = http.responseText;
}
};
http.send(params);
}
function sendToSearch(str) {
document.getElementById('qsearch').value = str;
document.getElementById('searchResults').innerHTML = '';
}