title: Create modal when use onclick event with AJAX
body: <p>I have a file, which needs to have 90 modals with lots of long texts, because I need to create a modal when a link is clicked. </p>
  
  <p><strong><em>index.php</em></strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;title&gt;Bootstrap 101 Template&lt;/title&gt;
  
      &lt;!-- Bootstrap --&gt;
      &lt;link href="inc/bootstrap.css" rel="stylesheet"&gt;
      &lt;script src="inc/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="inc/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;script&gt;            
              $(function(){
                  $('a').click(function(){
                      var link = $('#name').html(); // I need sent this to my calculator file
                      $.ajax({
                          url : "result.php",
                          type : "post",
                          dataType:"text",
                          data : {
                               name: link
                          },
                          success : function (a){
                              $('#result').html(a);
                          }
                      });
                  });
              });
          &lt;/script&gt;
          &lt;div id="result"&gt;&lt;/div&gt;
          &lt;a href="#" id="name"&gt;I need this text for php script&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><em>resuilt.php</em></strong></p>
  
  <pre><code>/* I used PHP becase i need more functions, this only a example how
   * to creat and call a modal after click on a link.
  */
  function create_modal($modal_ID = 'myModal')
  {
      return "&lt;div class='modal fade' id='$modal_ID' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'&gt;
                  &lt;div class='modal-dialog'&gt;
                    &lt;div class='modal-content'&gt;
                      &lt;div class='modal-header'&gt;
                        &lt;button type='button' class='close' data-dismiss='modal'&gt;&lt;span aria-hidden='true'&gt;&amp;times;&lt;/span&gt;&lt;span class='sr-only'&gt;Close&lt;/span&gt;&lt;/button&gt;
                        &lt;h4 class='modal-title' id='myModalLabel'&gt;Nhãn&lt;/h4&gt;
                      &lt;/div&gt;
                      &lt;div class='modal-body'&gt;
                        Nội dung
                      &lt;/div&gt;
                      &lt;div class='modal-footer'&gt;
                        &lt;button type='button' class='btn btn-default' data-dismiss='modal'&gt;Close&lt;/button&gt;
                        &lt;button type='button' class='btn btn-primary'&gt;Save changes&lt;/button&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;";
  }
  echo create_modal();
  ?&gt;
  </code></pre>
  
  <p>The result is, I need to click on the link two times to show my modal. But it can't close or does anything.</p>
  
  <p>Where did it go wrong? And is there any way to make my idea better?</p>