jQuery printout a json file onto a html site.

Discussion in 'HTML & Website Design' started by Philosophaie, Feb 6, 2017.

  1. #1
    I am trying to print out json1.json onto <div>.
    jQuery-1.4.1.js, jquery-1.4.2.min.js and json1.json exist in the same folder as the htm file.


    <script type="text/javascript" src="jquery-1.4.1.js"></script>
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
        <script>
            $(document).ready(function(){
                $("#search").click(function () {
                    $.getJSON("#json1.json", function(result){
                        $each(function(key,val){
                            if ($("#searchtext").val()=="jfgjrtjgh" && key=="first"){
                                $("#firstname").val(key.first);
                                $("#lastname").val(key.last);
                                $("#description").val(key.desc);
                            }
                        });
                      });            
                 });
            });
        </script>
    ...
    <div></div>
    Code (markup):
    //json1.json
    
    [
        {"first":"fgdfb", last":"dfghdfgh", "desc":"jjif"},
        {"first":"jdtyhjn", last":"hmbnmgh", "desc":"hfhhfyif"},
        {"first":"fgbnfgjthj", last":"tewgsdfgngh", "desc":"argrayif"},
        {"first":"kuykyky", last":"bfbffc", "desc":"lykghif"},
        {"first":"jfgjrtjgh", last":"dsfhngh", "desc":"pgkkgff"},
        {"first":"ghjjhb", last":"fdasfgh", "desc":"nfhdfhjif"},
        {"first":"ohhklhjb", last":"qsdwdgh", "desc":"vfrfeif"}
    ]
    Code (markup):
     
    Philosophaie, Feb 6, 2017 IP