Pass parameters to modal bootstrap via javascript

0

I have a system that has a web version, you can see it here: All in Your Hands . In it you will notice that there is a carousel for displaying more accessed content and in this carusel js used to open a modal bootstrap in the case of some content such as music and videos. The javascript function that is called to open the modal is this below:

function recommendedContentsDialodShow(){
    $('#recommendedContentsModal').on('hidden.bs.modal', function() {    


    }).modal('show');       
}

The problem is that I can not open the modal and display data on it using EL (ex: ${nomeMusica} ) without making a request and reloading the entire page. How could I do this without making a request by setting these parameters in the request scope? I have already tried features like c: set but it did not work ...

    
asked by anonymous 08.10.2014 / 17:04

1 answer

2

The smartest solution, in my opinion, is that you make a request for each open modal. But why, anyway?

  • Without request, you will have to store the data of the content you want to explode on the page itself, which is a waste of bandwidth for those who will not open

  • If the information you want to open in your modal is the same as the one you already have on your page, then here's an opportunity for you to rethink your UX , because you are replicating data unnecessarily;

  • Finally, if you definitely want to pass some variables into your modal, be aware that this is only possible if your recommendedContentsDialodShow() function is in the same scope as your page that has ${nomeMusica} . For example:

index.php :

<?php $nomeMusica = 'The Offspring – You're gonna go far, kid'; ?>

<script type="text/javascript">
  alert('<?php echo $nomeMusica; ?>');
</script>
  • That is, you will not be able to process your variable over different scopes - neither JavaScript nor PHP know how to do this. Also, understand that this mixture of languages, especially in this format, is bad. The ideal is to uncouple as much as possible one language from the other, without making a fruit salad in a specific file. So your solution is, if you invariably want to use $nomeMusica in your JavaScript, make sure your statement is at the same level as the calling function. Otherwise, in turn, use a $.ajax request - this, in addition to being an alternative that will solve your problem, is the most suitable option for your scenario.
08.10.2014 / 18:49