Php AJAX search with external JSON file <p>So Im trying to create an input field that displays results without the need of a refresh from an external JSON file. My current code works fine, however how would I achieve checking for results in an external JSON file instead of directly in the php file?</p> <p>My JSON file: (I'd like to display results from "name").</p> <pre><code>[ {"name" : "300", "year" : "1999", "plot" : "X", "run" : "200 min", "rated" : "PG-13", "score" : "10/10", "source" : "A", "id" : "000"}, {"name" : "200", "year" : "1999", "plot" : "X", "run" : "200 min", "rated" : "PG-13", "score" : "10/10", "source" : "A", "id" : "000"} ] </code></pre> <p>My html and Javascript:</p> <pre><code>&lt;script&gt; function showHint(str) { if (str.length == 0) { document.getElementById("txtHint").innerHTML = ""; return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } }; xmlhttp.open("GET", "gethint.php?q=" + str, true); xmlhttp.send(); } } &lt;/script&gt; &lt;p&gt;&lt;b&gt;Start typing a name in the input field below:&lt;/b&gt;&lt;/p&gt; &lt;form&gt; First name: &lt;input type="text" onkeyup="showHint(this.value)"&gt; &lt;/form&gt; &lt;p&gt;Suggestions: &lt;span id="txtHint"&gt;&lt;/span&gt;&lt;/p&gt; </code></pre> <p>gethint.php</p> <pre><code>&lt;?php //Instead of using these I'd like to use the external JSON file $a[] = "Anna"; $a[] = "Brittany"; $a[] = "Cinderella"; $a[] = "Diana"; // get the q parameter from URL $q = $_REQUEST["q"]; $hint = ""; // lookup all hints from array if $q is different from "" if ($q !== "") { $q = strtolower($q); $len=strlen($q); foreach($a as $name) { if (stristr($q, substr($name, 0, $len))) { if ($hint === "") { $hint = $name; } else { $hint .= ", $name"; } } } } // Output "no suggestion" if no hint was found or output correct values echo $hint === "" ? "no suggestion" : $hint; ?&gt; </code></pre>