function editPost(id) { $.ajax({ type: 'POST', url: '../Backend/controller/getPost.php', data: { id: id }, success:function (data) { Swal.fire({ title: 'Rediger Post', html: '
', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Rediger', focusConfirm: false, preConfirm: () => { const title = Swal.getPopup().querySelector('#title').value const desc = Swal.getPopup().querySelector('#description').value if (!title || !desc) { Swal.showValidationMessage(`Skriv noget i begge felter!`) } else { data.title = title; data.description = desc; } return {title: title, desc: desc} } }).then((result) => { if (result.isConfirmed) $.ajax({ type: 'POST', url: '../Backend/controller/update.php', data: {'id':id, 'upTitle': data.title, 'upDescription': data.description}, success:function () { Swal.fire( 'Posten er redigeret!', '', 'success' ).then(function() { document.getElementById(id).children[1].innerHTML = data.title; }) }, error:function (data) { Swal.fire( 'Posten kunne ikke blive redigeret', '', 'error' ) } }); }) }, error:function (data) { console.log(data); } }); /**/ }