|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PHP & AJAX Script problem
search.php
PHP Code:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Live zoeken in je database.</title> <script language="Javascript" type="text/javascript"> // Het script die daadwerkelijk het zoeken doet var url = "./scripts/search.php?q="; function handleHttpResponse() { // Hier wordt de output van het script gehaald. if (http.readyState == 4 && http.status == 200) { document.getElementById('results').innerHTML = http.responseText; } } var done = false; function liveSearch() { if (!done && http) { var term = document.getElementById('searchterm').value; document.getElementById('results').innerHTML = ""; http.open('GET', url + term, true); http.onreadystatechange = handleHttpResponse; done = true; http.send(null); } } function getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); </script> </head> <body> <form action="post"> <p>Zoekterm:</p> <input type="text" id="searchterm" value=""> <input type="button" id="search" value="Zoek!" onclick="liveSearch();"> </form> <div id="results"> </div> </body> </html> How can I make it so that when I would click on search again it clears all the current results and displays the newer results? Thanks in advance, Sam |
|
#2
|
||||
|
||||
|
it's because you're setting done to true when complete. why do you need this?
you can try this though Code:
function handleHttpResponse() {
// Hier wordt de output van het script gehaald.
if (http.readyState == 4 && http.status == 200) {
document.getElementById('results').innerHTML = http.responseText;
done = false;
}
}
__________________
Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter celery is tasteless - currently needing some UI time |
|
#3
|
|||
|
|||
|
Perfect!! Thanks mate!
![]() Works like a dream
|
|
#4
|
|||
|
|||
|
Also, to search I have to press the button. I can't press enter because i get redirected to "www.domain.com/post?"
Any tips? |
|
#5
|
|||
|
|||
|
Not a clue ^^
__________________
Corn is no place for a mighty warrior! |
|
#6
|
||||
|
||||
|
pressing enter submits your form, this line is wrong
Code:
<form action="post"> Code:
<form action="#" method="post">
__________________
Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter celery is tasteless - currently needing some UI time |
|
#7
|
|||
|
|||
|
Thanks - that worked. but now i've make it on keyup and down press that it displays results without even pressing the search button. (I removed the search button too)but how do i make that pressing enter doesn't do anything at all (at the moment it sort of refreshes the page).
|
|
#8
|
||||
|
||||
|
that's browser dependent behavior, IIRC, and you really shouldn't play with it (because fixing it in a browser may break your form in another, for example)
the best place to ask that is in the javascript forum, they might be able to give you some pointers.
__________________
Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter celery is tasteless - currently needing some UI time |
|
#9
|
||||
|
||||
|
Quote:
PHP Code:
|
|
#10
|
||||
|
||||
|
What about a browser with Javascript disabled, They would not be able to submit hte search form? Maybe use a discret image as a secondry option to submit the form?
__________________
Auckland, New Zealand, Web Design & Hosting. - Inbox Design Sheldon Lendrum, Technology, PHP, Mootools & More... Simple Site a Completely Dynamic site using text files, PHP and no mySQL. |
|
#11
|
||||
|
||||
|
Quote:
Code:
document.getElementById('searchterm').onkeyup = keyHit;
__________________
Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter celery is tasteless - currently needing some UI time |
|
#12
|
||||
|
||||
|
Quote:
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|