update database from html form using ajax

后端 未结 3 518
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 06:24

I would like some help with ajax. I would like to update a php file which will update a database. I have a form which send the selected check box to a php file which then up

3条回答
  •  被撕碎了的回忆
    2021-01-20 06:58

    document.getElementByName not a javascript function, try document.getElementById() instead

    You can do this

    Javascript:

    function myFunction() {
    var boiler = document.getElementById("boiler").value;
    var niamh = document.getElementById("niamh").value;
    // Returns successful data submission message when the entered information is stored in database.
    
    // i dont practice using url string in ajax data as it can be compromised with a quote (') string, instead i am using json
    
    // AJAX code to submit form.
        $.ajax({
        type: "POST",
        url: "updateDB.php",
        data: {
           boiler: boiler,
           niamh: niamh
        },
        cache: false,
        }).done(function() {
            alert('success');
        }); // i do this because some jquery versions will deprecate the use of success callback
    }
    

    And you are getting to a post so change the $_GET in you php file to $_POST

提交回复
热议问题