sunicani Posted August 24, 2009 Share Posted August 24, 2009 AJAX combined with xmlHttpRequest()?well, I've seen some of topics about whether a better solution for fast response on server via Javascript or PHP combined with HttpRequest() function in order to load data to dynamic page!in my opinion, I want to use AJAX with xmlHttpRequest.to be frank, I am a learner for HttpRequest(), and, want an example for this function. to be specified, how to display data via this way?thanks a lot, any experts! Link to comment Share on other sites More sharing options...
jeffman Posted August 24, 2009 Share Posted August 24, 2009 Start with this tutorial: http://www.w3schools.com/ajax/default.aspThe specific answer to your question is on this page http://www.w3schools.com/ajax/ajax_xmlhttprequest.asp under the heading The responseText property Link to comment Share on other sites More sharing options...
justsomeguy Posted August 24, 2009 Share Posted August 24, 2009 There are also a few useful things here:http://w3schools.invisionzone.com/index.ph...st&p=116840 Link to comment Share on other sites More sharing options...
sunicani Posted August 25, 2009 Author Share Posted August 25, 2009 There are also a few useful things here:http://w3schools.invisionzone.com/index.ph...st&p=116840 yeah, thank you all and, Javascript file, Asp File, and xml file, the three file could be combined for displaying product information? Link to comment Share on other sites More sharing options...
sunicani Posted August 28, 2009 Author Share Posted August 28, 2009 again, I can't figure out where to start with httprequest for data in MySQL, use xmlHttpRequest()?, or AJAX coe mbined with HttpRequest()?, or just pure PHP combined with MySQL?by the way, it seems xml is more faster? however, so many nodes with be complicated?in my opinion, I prefer to pure Javascript (AJAX) alike, or just PHP+MySQLany experts who could guide me in detail.thanks you all, experts, yeah, my mates all here! Link to comment Share on other sites More sharing options...
Ingolme Posted August 28, 2009 Share Posted August 28, 2009 There is no "HttpRequest" object in Javascript. It's called "XmlHttpRequest". But ignore the XML part because it has little to do with XML.The "XmlHttpRequest" object is what you use to make HTTP requests. Link to comment Share on other sites More sharing options...
Citydev Posted August 28, 2009 Share Posted August 28, 2009 I am a learner for HttpRequest(),Do you mean the PHP function? If so I think that makes a call in the PHP script ie before the page gets to your browser so is not really relevant to Ajax. Link to comment Share on other sites More sharing options...
GerryH Posted August 28, 2009 Share Posted August 28, 2009 ...in my opinion, I prefer to pure Javascript (AJAX) alike, or just PHP+MySQLWhat works for me using javascript and PHP is something like this (this is example of filtering a name search from my site using AJAX;var xmlHttpfunction findName(str){ var x = document.getElementById("txtHint"); if (str.length == 0) { document.getElementById("txtHint").style.display="none"; return; } document.getElementById("txtHint").style.display=""; xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="yourPHPScipt.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; }}function GetXmlHttpObject(){ var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp;} And the PHP script; <?include("/includes/db.php");$queryString = $_GET["q"];function is_upper($input) { return ($input == strtoupper($input));}if (strlen($queryString) > 0){ echo "<menu name=cid>"; if (is_numeric($queryString)) $query = mysql_query("SELECT * FROM youtable WHERE id like '$queryString%' order by id limit 10"); else if (is_upper($queryString)) $query = mysql_query("SELECT * FROM yourtable WHERE initials like '$queryString%' order by initials limit 10"); else $query = mysql_query("SELECT * FROM yourtable WHERE name like '%$queryString%' order by name limit 20"); $i=0; if($query) { while ($result = mysql_fetch_object($query)) { $aid = sprintf("id%d", $i++); $string = sprintf("%-7.7s %s (%s)", $result->cid, $result->name, $result->initials); echo "<li class=\"suggestionListli\" onmouseOver=\"mouseOver($i)\" onmouseOut=\"mouseOut($i)\" id=$i onclick=\"getCid('$result->cid', '$string')\">$string</li>"; } } echo "</menu>";}?> And finally the HTML snippet: <html>...<input class="bold" type="text" size="45" id="inputString" name="searchbox" onkeyup="findName(this.value);" /></p><div style="display: none;" class="suggestionsBox" id="txtHint"></div><br>...</html> NOTE: forgive the sprintf functions, I'm a seasoned C programmer, old habits die hard! Link to comment Share on other sites More sharing options...
sunicani Posted August 29, 2009 Author Share Posted August 29, 2009 oh! good, thank you very much and, let me try it first, so excited, mate Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.