PHP expert |
|
Heb een beetje liggen 'kloten' en het is gelukt om er iets van te maken. Zo kan je dus dynamisch meerdere gegevens sturen naar een pagina naar keuze waarvan de inhoud in een div naar keuze komt te staan.
<script language="javascript">
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
req = NULL;
alert('Probleem met het aanmaken van hetXMLHttpRequest object');
}
return req;
}
var http = createRequestObject();
/* BEGIN IE BUG FIX */
var aDiv = new aDiv();
function setDiv(theDiv) {
this.theDiv = theDiv;
}
function getCurrentDiv() {
if(this.theDiv != "")
return this.theDiv;
else
alert('Geen div geset');
}
function aDiv(theDiv) {
this.theDiv = theDiv || '';
this.set = setDiv;
this.getCurrent = getCurrentDiv;
}
/* EIND IE BUG FIX */
function sendRequest(theDiv, page, gets, values) {
if(gets.length != values.length) {
alert('sendRequest: arg3 and arg4 != length');
} else {
var pageString = page +'?';
aDiv.set(theDiv);
for (i = 0; i < gets.length; i++) {
pageString += gets[i] +'='+ values[i] +'&';
}
http.open('get', pageString);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
if(http.responseText) {
document.getElementById(aDiv.getCurrent()).innerHTML = http.responseText;
} else {
document.getElementById(aDiv.getCurrent()).innerHTML = " ";
}
} else {
document.getElementById(aDiv.getCurrent()).innerHTML = " ";
}
}
</script>
<table width="100%">
<tr>
<td valign="top" width="301">
<input type="text" size="50" name="zoek" onkeyup="sendRequest('zoek_resultaten', 'search.php', Array('zoek'), Array(this.value));" />
</td>
<td valign="top">
<div id="zoek_resultaten" style="border:1px solid #000000"></div>
</td>
</tr>
</table>
<script language="javascript"> function createRequestObject() { var req; if(window.XMLHttpRequest){ req = new XMLHttpRequest(); } else if(window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } else { req = NULL; alert('Probleem met het aanmaken van hetXMLHttpRequest object'); } return req; } var http = createRequestObject(); /* BEGIN IE BUG FIX */ var aDiv = new aDiv(); function setDiv(theDiv) { this.theDiv = theDiv; } function getCurrentDiv() { if(this.theDiv != "") return this.theDiv; else alert('Geen div geset'); } function aDiv(theDiv) { this.theDiv = theDiv || ''; this.set = setDiv; this.getCurrent = getCurrentDiv; } /* EIND IE BUG FIX */ function sendRequest(theDiv, page, gets, values) { if(gets.length != values.length) { alert('sendRequest: arg3 and arg4 != length'); } else { var pageString = page +'?'; aDiv.set(theDiv); for (i = 0; i < gets.length; i++) { pageString += gets[i] +'='+ values[i] +'&'; } http.open('get', pageString); http.onreadystatechange = handleResponse; http.send(null); } } function handleResponse() { if(http.readyState == 4 && http.status == 200){ if(http.responseText) { document.getElementById(aDiv.getCurrent()).innerHTML = http.responseText; } else { document.getElementById(aDiv.getCurrent()).innerHTML = " "; } } else { document.getElementById(aDiv.getCurrent()).innerHTML = " "; } } </script> <table width="100%"> <tr> <td valign="top" width="301"> <input type="text" size="50" name="zoek" onkeyup="sendRequest('zoek_resultaten', 'search.php', Array('zoek'), Array(this.value));" /> </td> <td valign="top"> <div id="zoek_resultaten" style="border:1px solid #000000"></div> </td> </tr> </table>
|