[[oktatas:web:jquery:ajax|< AJAX]] ====== jQuery .ajax metódus ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2021 * [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Todo ===== TODO

TODO

$.ajax('php/getTodos.php', { success: function(data, status, xhr) { let list = $.parseJSON(data) initList(list); } }); function initList(list) { $.each(list, function(index, value){ $('#todolist').append( '
  • ' + value['description'] + '
  • '); }); }
    $('#addButton').click(function(){ var newtodo = $('#newtodo').val(); $('#newtodo').val(''); $('#todolist').append('
  • ' + newtodo + '
  • '); var jsonNewTodo = JSON.stringify(newtodo); $.ajax( { type: 'post', url: 'php/insertTodo.php', data: jsonNewTodo, success: function(result) { console.log(result); } }); });
    fetch_assoc(); $datar[] = $row); closeDb($conn); return $datar; } function beszurTodo($todo) { $conn = connectDb(); $sql = " insert into todos (description) values (?) "; if ($stmt = mysqli_prepare($conn, $sql)) { mysqli_stmt_bind_param($stmt, "s", $todo ); mysqli_stmt_execute($stmt); error_log(mysqli_stmt_error($stmt)); mysqli_stmt_close($stmt); echo "siker"; } else { echo "Hiba a beszúrás során!"; } closeDb($conn); }