JQuery loop display array name and value
I am trying to build a loop where it will display like this:
Company Name ABC Inc
Mailing Address Springfield ZZ 12345
Phone 1 (555) 555-5555
Fax 1 (555) 555-5556
My current code is not looping for each object just displaying once.
Json Encode output
[{"Company Name":"ABC Inc","Mailing Address":"Springfield ZZ 12345","Phone":"1 (555) 555-5555","Fax":"1 (555) 555-5556","Email Address":"
test@test.com"}]
HTML Code
- <!-- Company Details -->
- <div id="company">
- </div>
- <!-- /JS Company Details -->
- <script type='text/javascript'>
- $(document).ready(function () {
- /* call the php that has the php array which is json_encoded */
- $.getJSON('php/company.php', function (company) {
- /* data will hold the php array as a javascript object */
- $.each(company, function (company_key, company_val) {
- $("#company").append(
- '<div class="row">'+
- '<div class="col-md-6">'+
- '<div class="form-group">'+
- '<label class="control-label col-md-4"> Array Name</label>'+
- '<div class="col-md-8">'+
- '<p class="form-control-static"> Array Value </p>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '</div>'
- );
- });
- });
- });
- </script>
- <!-- /JS Company Details -->