php - How to implement an AJAX op while creating a search bar? -
I was trying to create a search bar using AJX, which searches for user in database, AJX works fine Has been doing; It displays the right message when no one is typed or no user is found. The problem is, even though users found that it does not show any user. This is a php file:
& lt ;? Php header ('content-type: text / xml'); Echo '& lt ;? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"? & Gt; '; Require_once ("include / connection.php"); Echo '& lt; Feedback & gt; '; User $ = $ _ receive ['user']; If ($ user == "") {"echo username" echo; } And {$ query = "select from email id where e-mail_ id = {$ user}"; $ User_result = mysql_query ($ query, $ connection); If ($ user_result) {echo "yes {$ user} exists"; } Else {resonant "There is no such user that {$ user} exists"; }} Echo '& lt; / Response & gt; '; ? & Gt;
I am not including the function to create xml.http objects but this is the other javascript code:
function start () {if (xmlHttp) { Try {if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4} {user = encoder component (document.getElementById ("user_input"). Value); xmlHttp.open ("GET", "? Search.php User = "+ user, true); XmlHttp.onreadystatechange = mainFunctionHandler; xmlHttp.send (zero);} Else {setTimeout ('start ()', 1000);}} hold (e) {warning (eStosting () );}}} Function mainFunctionHandler () {if (xmlHttp.readyState == 4) {if (xmlHttp.status == 200) {xmlResponse = xmlH ttp.responseXML; XmlDocumentElement = xmlResponse.documentElement; Message = xmlDocumentElement.firstChild.data; document.getElementById ( "divD") innerHTML = message. setTimeout ( 'Start ()', 1000);} else {alert ( "Something went wrong Gone ");}}}}
First of all, mysql_ * functions dislikes and You should not use it. It read:
However, this situation must have PHP in (many lines to $ result to check
. This would be true if it's 0 hits / lines ):
& lt ;? Php header ('content-type: text / xml'); Echo '& lt ;? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"? & Gt; '; Require_once ("include / connection.php"); Echo '& lt; Feedback & gt; '; User $ = $ _ receive ['user']; If ($ user == "") {"echo username" echo; } And {$ query = "select from email id where e-mail_ id = {$ user}"; $ User_result = mysql_query ($ query, $ connection); If (mysql_num_rows ($ user_result) & gt; 0) {echo "Yes {$ user} exists"; } Else {resonant "There is no such user that {$ user} exists"; }} Echo '& lt; / Response & gt; '; ? & Gt;
Comments
Post a Comment