user1504222
user1504222

Reputation: 267

Fech data inside a modal (from a table) into href

I use this function to fill in text fields inside a modal.

    $(document).on('click', '.edit_followup', function(){ 
        $('#edit_followup').modal('show');
        //alert ('working!');

        const $tr = $(this).closest('tr');
        var data = $tr.children("td").map(function() {
            return $(this).text();
        }).get();

        console.log(data);

        $('#opportunity_follow_up_id').val(data[0]);
        $('#opportunity_follow_up_opportunities_id').val(data[1]);
        $('#opportunity_follow_up_message').val(data[2]);
        $('#none').val(data[3]);
        $('#opportunity_follow_up_next_date').val(data[4]);
        $('#opportunity_follow_up_next_time').val(data[5]);
        $('#opportunity_follow_up_completed').val(data[6]);
       alert (data[6]);
        if (data[6] == '1'){ $('#opportunity_follow_up_completed').attr('checked', 'checked'); }
    });

In this modal i have addedd a DELETE BUTTON

<a href="action/delete.php?fid=<?php echo $opportunity_follow_up_id; ?>&id=<?php echo $opportunity_follow_up_opportunities_id; ?>">
    <button type="button" class="btn btn-danger">
       <i class="bx bx-x d-block d-sm-none"></i><span class="d-none d-sm-block"> Delete</span>
    </button>  
</a>

How to passing values:

$('#opportunity_follow_up_id').val(data[0]); $('#opportunity_follow_up_opportunities_id').val(data[1]);

To href?:

href="action/delete.php?fid=#opportunity_follow_up_id&id=#opportunity_follow_up_opportunities_id

Thanks all of you.

Upvotes: 1

Views: 40

Answers (1)

Chase
Chase

Reputation: 3116

You should not make DELETE requests via GET request (i.e. a standard anchor link). A HTTP request using the DELETE method should be used. See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1

Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.

In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.


But if you wish to continue this technique, you can change your anchor's href like so:

$('#edit_followup a').attr('href', `action/delete.php?fid=${data[0]}&id=${data[1]}`);

Upvotes: 1

Related Questions