Ajax request with bootstrap modal in php

后端 未结 1 896
逝去的感伤
逝去的感伤 2021-01-26 03:05

I am trying to display some information in a bootstrap modal based on some values.

Here is the work flow

1.Display Hyperlinks in a loop with a title.

2.W

1条回答
  •  迷失自我
    2021-01-26 03:58

    Assuming your foreach outputs links like this:

     title
     another title
    

    You could then invoke the click method instead of show.bs.modal in order to use $(this).

    So your code will change to:

     $('.btn-block').on('click',function(){
        var id = $(this).data('id');
        alert(id);
        $('.modal-body').html('loading');
    
           $.ajax({
            type: 'POST',
            url: '../Functions/form_process.php?action=getdetailsbyid',
            data:{id: id},
            success: function(data) {
              $('.modal-body').html(data);
            },
            error:function(err){
              alert("error"+JSON.stringify(err));
            }
        });
     });
    

    Here is an Example


    Otherwise you will need to use a unique id on all your outputted links (which you can do using a counter in your foreach)

    0 讨论(0)
提交回复
热议问题