This article has been dead for over three months
You
// JavaScript Document
/*
@Author SkyDriver - Damjan Krstevski
@Country/City: Macedonia, Skopje
@Date 26/2/2010 - 10:31 AM
@Description: Ajax library...
@License: Freeware, you can use, change and redistributed this library.
*/
var xmlhttp;
/// <summary> Changing the contents of a tag </summary>
/// <param name="url"> URL/Resource File with content who want to change </param>
/// <param name="target">ID name of DIV tag where you want to make change </param>
/// <api> javascript: addContent('myfile.php', 'mydivid'); </api>
function addContent(url, target) {
try {
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert (error);
return;
}
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
document.getElementById(target).innerHTML = xmlhttp.responseText;
} catch (e) {
alert("An error occurred.\nDetails: " + e);
}
}
/// <summary> Reading records from database/file and changing the contents of a tag </summary>
/// <param name="str"> Input string (search string) </param>
/// <param name="url"> URL/Resource File with the code for getting the information from the database/file </param>
/// <param name="target">ID name of DIV tag where you want to show results </param>
/// <api> onClick="getResults('my search string', 'getResults.php', 'mydivid')" </api>
function getResults(str, url, target) {
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert ("Your browser does not support XMLHTTP!");
return;
}
url = url + "?q=" + str;
url = url + "&sid=" + Math.random();
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
document.getElementById(target).innerHTML = xmlhttp.responseText;
}
/// <summary> Help with search (suggest) </summary>
/// <param name="str"> Input string (search string) </param>
/// <param name="url"> URL/Resource File with the code for getting the information from the database/file </param>
/// <param name="target">ID name of DIV tag where you want to show results </param>
/// <api> onkeyup="suggest(this.value, 'getSuggest.php', 'mydivid')" </api>
function suggest(str, url, target) {
if (str.length == 0) {
document.getElementById(target).innerHTML = "";
return;
}
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert ("Your browser does not support XMLHTTP!");
return;
}
url = url + "?q=" + str;
url = url + "&sid=" + Math.random();
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
document.getElementById(target).innerHTML = xmlhttp.responseText;
}
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}