I have a JSON file in this form {"Name":"wefgew"; "Birthday": "21"; "City": "qefqwef"} {"Name":"wefgew"; "Birthday": "21"; "City": "qefqwef"} {"Name":"wefgew"; "Birthday": "21"; "City": "qefqwef"} . I need such ajax easily that I would write Names, Days, Cities into my span (approximately <span class="params on" id="Name">wefgew</span ). I would like a similar example, I would be grateful for any help, thanks in advance!
JS block with which I receive data from the input and transfer php to save
<script> $('#btn_save').on('click',function(){ var textField = $('#textField').val(); var textBirthday = $('#textBirthday').val(); var textCity = $('#textCity').val(); var str = '{"Name":"' +textField +'"; "Birthday": "' + textBirthday + '"; "City": "' + textCity + '"}'; $.ajax({ type: "POST", url: 'test.php', data: {'str':str}, success: function(data){ alert('Successfully saved'); }, error: function(data) { alert('Error'); }, }); }); </script> Php file <?php file_put_contents('some_file.json', $_POST['str']);