ra_ie_darkness Posted April 7, 2013 Share Posted April 7, 2013 Hello, I am new to ajax and javascript and am trying to create a search engine This is the javascript code var XMLHttpRequestObject = false; if(window.XMLHttpRequest) { XMLHttpRequestObject = new XMLHttpRequest(); } else if(window.ActiveXObject) { XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } function showresult(search) { if(XMLHttpRequestObject) { var obj = document.getElementById("showresult"); XMLHttpRequestObject.open("POST","index.php",true); XMLHttpRequestObject.setRequestHeader("Content-type","application/x-www-form-urlencoded"); XMLHttpRequestObject.onreadystatechange = function() { if(XMLHttpRequestObject.readystate == 4 $$ XMLHttpRequestObject.status == 200) { obj.innerHTML = XMLHttpRequestObject.responseText; } } XMLHttpRequestObject.send("search=" + search); } //alert("You clicked me"); } PHP + HTML: <form method="post" name ="searchform" id="idsearchform" > <input type="text" name="search"/> <input type="button" name="starts" value="search" onclick="fun(search)"/> </form> <?php if(isset($_POST['starts'])) { $keyword = $_POST['search']; $search_q = mysql_query("Select * from products where pname like '%$keyword%'"); if(mysql_num_rows($search_q)!=0) { while($result = mysql_fetch_array($search_q)) { ?> <div id="showresult"> <?php $name = $result['pname']; echo "$name<br/>"; } } }?> </div> I don't get the search results when i click the search button. What is the issue here Quote Link to comment https://forums.phpfreaks.com/topic/276636-ajax-search/ Share on other sites More sharing options...
ra_ie_darkness Posted April 7, 2013 Author Share Posted April 7, 2013 correction <form method="post" name ="searchform" id="idsearchform" > <input type="text" name="search"/> <input type="button" name="starts" value="search" onclick="showresult(search)"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/276636-ajax-search/#findComment-1423371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.