How can I get the data attribute from a php variable?

后端 未结 2 2036
猫巷女王i
猫巷女王i 2021-01-16 00:29

I have a form that can delete records from a MySql database using ajax and jQuery. I\'m trying to get the jQuery to only select the relevant record passed to it and not just

2条回答
  •  感情败类
    2021-01-16 01:05

    First in your PHP do something like this, you add the data attributes to your delete button since you are not actually submitting a real form. I also moved the deleteReview class to the button.

    print '';
    

    Then, in your jQuery, update click event callback like so:

    $(".deleteReview").click(function (e) {
        e.preventDefault();
        var username=$(this).data('username');
        var film_id=$(this).data("film-id");
        var id=$(this).data('id');
        /* the rest of your code */
    

    The data attributes become accessible easily with jQuery using $(this).data('some-attribute-name')

提交回复
热议问题