OZONE Asylum
Forums
Server-Side Scripting - Oh my!
AJAX xmlhttp.responsetext and php
This page's ID:
31319
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
What i am trying to accomplish is to send an xmlhttp.request to a php page which has an array of name. if the request matches any name in the array it will return that name so i can test for equality. It works well with one name. my question is can i send back more than just one name.. like lets say a name and a message and check equality for the name and display the message. basically im asking can the xmlhttp.responsetext be used like an object with different properties so i can pull back different things to set as variables in my javascript. my code looks like this. 1. First the html page with the form and input fields. [code] <html> <head> <script src="clienthint.js"></script> </head> <body> <form name="form1"> First Name: <input type="text" id="txt1" onkeyup="showHint(this.value)" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html> [/code] 2. Next will be my javascript file [code] var xmlhttp function showHint(str){ if (str.length==0){ document.getElementById("txtHint").innerHTML=""; return; } xmlhttp=GetXmlHttpObject(); if (xmlhttp==null){ alert ("Your browser does not support XMLHTTP!"); return; } var url="gethint.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged(){ if (xmlhttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlhttp.responseText; if (document.getElementById("txt1").value == xmlhttp.responseText){ document.getElementById("txt1").style.backgroundColor = "#FFFF99"; } else { document.getElementById("txt1").style.backgroundColor = "#FFFFFF"; } } } function GetXmlHttpObject(){ if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject){ // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } [/code] 3. And last is the php page [code] <?php // Fill up array with names $a[]="Anna"; $a[]="Brittany"; $a[]="Cinderella"; $a[]="Diana"; $a[]="Eva"; $a[]="Fiona"; $a[]="Gunda"; $a[]="Hege"; $a[]="Inga"; $a[]="Johanna"; $a[]="Kitty"; $a[]="Linda"; $a[]="Nina"; $a[]="Ophelia"; $a[]="Petunia"; $a[]="Amanda"; $a[]="Raquel"; $a[]="Cindy"; $a[]="Doris"; $a[]="Eve"; $a[]="Evita"; $a[]="Sunniva"; $a[]="Tove"; $a[]="Unni"; $a[]="Violet"; $a[]="Liza"; $a[]="Elizabeth"; $a[]="Ellen"; $a[]="Wenche"; $a[]="Vicky"; //get the q parameter from URL $q=$_GET["q"]; //lookup all hints from array if length of q>0 if (strlen($q) > 0){ $hint=""; for($i=0; $i<count($a); $i++){ if (strtolower($q)==strtolower($a[$i])){ $hint=$a[$i]; } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint == ""){ $response="no suggestion"; } else{ $response=$hint; } //output the response echo $response; ?> [/code] any ideas/solutions will be greatly appreciated. Thank you in advance
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail