M
M
mzhanarys2016-06-17 09:45:58
JavaScript
mzhanarys, 2016-06-17 09:45:58

Displaying json file, adding new lines to existing json file?

This is how I display it now. Result -> [object Object],[object Object],[object Object]

$(document).ready(function(){                          
    $('#click').click(function(){                    
        $.getJSON('myJson.json', {}, function(json){  
           
                                                         
            $('#see').append('To: '   + json +  '<br/>');
                           
        });                
    })
});

Так я отправляю данные. Нужно еще что бы при каждом клике добавлялась новая строка с данными. 
var arr = [
     			{"name": "Вася", "age": 20},

     			{"name": "Петя", "age": 22},

     			{"name": "Таня", "age": 18}

     			];

   

       			$.ajax({

      			url: 'stat.php',
      
      			type: 'POST',
      
      			data: {myJson: JSON.stringify(arr), fileName: 'myJson.json'}
      
    			});

Это php
<?php
file_put_contents($_POST['fileName'], $_POST['myJson']);
?>


I can't figure out how to display the attributes and add new lines to the json file without erasing the old ones.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question