thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Delete button not working, $.get() function supposedly does not exist? #251

Open phodmin opened 6 years ago

phodmin commented 6 years ago

So I'm trying to implement a delete button for the pages page as in Videos 68-70 but even though I checked all the code, did everything step by step and checked it is written the same way in this code repository, it just does not seem to work.

The problem FireBug states when I try to debug it is that the Javascript function $.get() does not exist, but Alan uses it the same way in his code. I'm sending related classes too.

js.php

<?php

//Javascript:

?>
<!-- JQuery -->
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>

<!-- JQuery UI -->
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- Bootstrap JQuery -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<!-- Bootstrap Ajax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<!-- Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<!-- Tiny MCE -->
<script src="js/tinymce/tinymce.min.js"></script>
<!-- Dropzone JS -->
<script src="js/dropzone.js"></script>

<script>

    $(document).ready(function(){

        $("#console-debug").hide();

        $("#btn-debug").click(function(){

            $("#console-debug").toggle();

        });

        $(".btn-delete").on("click", function(){

            var selected = $(this).attr("id");
            var pageid = selected.split("del_").join("");

            var confirmed = confirm("Are you sure you want to delete this page?");

            if(confirmed == true){

                $.get("ajax/pages.php?id="+pageid);

                $("#page_"+pageid).remove();

            }

                //alert(selected);

            })

    });

    tinymce.init({
    selector: ".editor",
    theme:"modern",
    plugins: [
        "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
        "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
        "save table contextmenu directionality emoticons template paste textcolor code"
        ],
    content_css:"css/content.css",
    toolbar: "code | insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview"
    /*style_formats:[
        {title: 'Bold text',inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color:'#ff0000'}},
        {title: 'Red header',block: 'h1', styles: {color:'#ff0000'}},
        {title: 'Example 1',inline: 'span', classes: 'example1'}},
        {title: 'Example 2',inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1',selector: 'tr', classes: 'tablerow1'},
    ] 
*/
    });

</script>

pages.php (in ../admin/ajax/pages.php)

<?php

include('../../config/connection.php');

$id = $_GET['id'];

$q = "DELETE FROM pages WHERE id = $id";
$r = mysqli_query($dbc,$q);

if($r){
    echo 'Page Deleted';
} else{
    echo 'There was an error...<br>';
    echo $q.'<br>';
    echo mysqli_error($dbc);
}

?>

Neither the visual deletion nor the database deletion doesnt work and $.get seems to be the problem, but I dont know why, pls help.

creptor commented 6 years ago

I recommend you to use the full version of jQuery (not the slim), at least if you're not sure of the elements you're using. Please try to implement it on your on and try again.

Google jQuery, there's a lot of information for it.

phodmin commented 6 years ago

Thanks! I simply removed the Bootstrap JQuery link in js.php and it works, I guess the slim version somehow had overridden the full version, dunno.