HTML/Javascript search function with AJAX -
i've created webpage want users able search word/term stored in csv file, , if term found full line line entry returned , displayed user (ideally in table format, otherwise textarea do).
but need using ajax, , cant use php (unfortunately, otherwise wouldn't asking question).
so far have table form/input/button, , i've got code read file, i'm bit stuck bringing both together. know should easy thing do, i've spend lot of time going through tutorials , online questions havent been able find similar.
if knows of tutorials covers this, or can out code below appreciated.
<table> <tr><td>enter search term: <input type="text" name="searchword" /> <input type="button" name="searchbutton" value="search" onclick="contentdisp();"> </td></tr> <tr><td><textarea id="contentarea" rows="40" cols="60"></textarea></td></tr> </table> //currently using text area ideally displayed in table <script type="text/javascript"> function contentdisp() { $.ajax({ url : "file.csv", success : function (data) { $("#contentarea").html(data); // think needs go in here, grab search term above , display file contents using term, possibly 'contain' */ } }); } </script>
it possible strictly via javascript using strpos , indexof functions (indexof starting point, while other string delimiter(s) ).
it possible task php if feel comfortable it, if you're restricted domain-origin restriction, take @ jsonp, stands json padding - means you'll need wrap result in javascript function.
good luck.
Comments
Post a Comment