1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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