Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load dynamic URL via modal

Let's say I have the following link that's generated X times by a loop.

<a class="btn" data-toggle="modal" data-target="#view_more" href="/item/view/<?php echo $item_id; ?>">Launch Modal</a>

Here's the JS script that initiates the modal.

$(document).ready(function () {
    $('#view_more').modal({
        remote: '/item/view/1',
        show:false
}); // Start the modal

It works when the remote url is hardcoded, but I would like it to be dynamic depending on what gets passed to it.

like image 371
sdot257 Avatar asked Sep 09 '12 15:09

sdot257


1 Answers

The Modal plugin executes the load() method in it's constructor, so really the only way to change the remote content of a Modal (other than manually doing the AJAX yourself) is to destroy it before doing another call:

$('#view_more')
  .removeData('modal')
  .modal({
    remote: someURL,
    show: false
  });

There are more details in answer to a similar post: Twitter bootstrap remote modal shows same content everytime

like image 65
merv Avatar answered Oct 30 '22 13:10

merv