Showing ajax call result in bootstrap modal

亡梦爱人 提交于 2019-12-04 09:38:20

You are binding the click event when the modal gets shown and you never show the modal so the click handler never gets bound.

You can do something like this:

$('.see-user').on('click', function(e) {
    e.preventDefault();
    var id = $(this).data('id');
    $.ajax({
        url:  'getUser',
        type: 'POST',
        data: {id: id},
        success: function(html){
            $('#seeProfile .modal-body p').html('test');
            $('#seeProfile').modal('show');
        },
        error: function(){
            alert("error");
        }  
    });  
});

If you do want to add the click handler when the modal gets shown, you need to use the appropriate handlers. You can find them here (below Events).

You should replace

 $('#seeProfile .modal-body .p').html('test');

By

 $('#seeProfile .modal-body p').html('test');

Because you're are looking for a class called 'p' if you insert a dot before. For a html tag <p></p> you just have to write 'p' in the selector.

And complete with the "$('#seeProfile').modal('show');" to show the modal.

Try this (work for me):

This will show the modal:

        $('Your button').on('click',function(e){
            e.preventDefault();
            $('your modal').modal('show');
        });

Then this will bind the modal show event:

( you can use show.bs.modal or shown.bs.modal the only differences are the timing of the event launch)

      $('your modal').on('show.bs.modal', function(e) {
          e.preventDefault();
          //ajax call here!!
      });

Try this:

$('#seeProfile .modal-body p').html('test');

Note that i removed . (dot) you had before p.

Tried using class name.

$(document).on("click", ".getAndUploadButClass", function() {
    alert("Before laoding the image making ajax call to load the images ");
    $('#picturemyModal').modal('show');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!