javascript - showing a search result using Ajax -


i trying use ajax display result of search not working , cannot find out why. here .html file contain ajax too.

js

function showsearchresult() {     alert('beginning');     if (document.getelementbyid("search").value == "") {         document.getelementbyid("searchresult").innerhtml = "";         return;     }     try {         xhr = new xmlhttprequest();     } catch (e) {         xhr = new activexobject("microsoft.xmlhttp");     }     // handle old browsers     if (xhr == null) {         alert("ajax not supported browser!");         return;     }     var string = document.getelementbyid("search").value;            var url = "quote4.php?search=" + string;       xhr.onreadystatechange = handler;     xhr.open("get", url, true);     xhr.send(null); }  function handler() {      // handle loaded requests     if (xhr.readystate == 4) {         if (xhr.status == 200) document.getelementbyid("searchresult").innerhtml = xhr.responsetext;          else alert("error ajax call!");     }  } 

html

<h1>live search</h1>  <form>     <input id="search" size="100" type="search"> <input id="submit"     onclick="showsearchresult(); return false;" type="button" value="go"> </form>  <div id="searchresult"></div>        

php

<? // pretend server slow   // try quote $handle = @fopen("http://download.finance.yahoo.com/d/quotes.csv?s={$_get['search']}&f=e1l1hg", "r"); if ($handle !== false) {     $data = fgetcsv($handle);     if ($data !== false && $data[0] == "n/a")     {         print("price: {$data[1]}");         print("<br />");         print("high: {$data[2]}");         print("<br />");         print("low: {$data[3]}");     }     fclose($handle); } ?> 

i cannot find out problem when open html file , search example mic won't result , nothing happen.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -