AJAX update MYSQL database using function called from HTML generated from PHP

前端 未结 2 1102
借酒劲吻你
借酒劲吻你 2020-12-19 07:41

I have a php page generating and displaying a table. for the last row in the table i want to display an image with an \'onclick\' function attached. this will send the usern

2条回答
  •  余生分开走
    2020-12-19 08:15

    The jQuery.ajax() function expects an object to be passed; you need to use { and } to begin and end your object literal. What you currently have is invalid JavaScript syntax, if you checked your browser's developer tools you'd see an error indicating that. So:

    $.ajax(
        url: "update.php",
        type: "POST",
        data: {
            'username': user,
            'liked': '1'
        },
        success: function () {
            alert("ok");
        }
    );
    

    should be

    $.ajax({ // added {
        url: "update.php",
        type: "POST",
        data: {
            'username': user,
            'liked': '1'
        },
        success: function () {
            alert("ok");
        }
    }); // added }
    

提交回复
热议问题