Show modal content from another page within same pages popup












0















Similar questions like this has been posted before but none solved my issue. I'm trying to get enrollments.php page to show as a modal popup within index.php page



index.php



<button class="sess_btn sess_btn1" id="btn_enrol">Enrollments</button>  
<div id="enrolModal"></div>

<script>
$(document).ready(function() {
//button modal
$('#btn_enrol').click(function(){
//using ajax post
$.post('enrollments.php',function() {
$('#enrolModal').html(); //Fill DIV enrolModal with enrollments.php content
})
//Calling Modal
$('#myModal').modal('show');
})
})
//-------------
</script>


enrollments.php



<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>

</div>


Also, when I try to click on the button several times there are quick blinks on the browser window. Any help will be appreciated, thanks.










share|improve this question

























  • Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

    – charlietfl
    Nov 23 '18 at 2:28













  • In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

    – Randy Casburn
    Nov 23 '18 at 2:30











  • Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

    – Moses
    Nov 23 '18 at 2:56
















0















Similar questions like this has been posted before but none solved my issue. I'm trying to get enrollments.php page to show as a modal popup within index.php page



index.php



<button class="sess_btn sess_btn1" id="btn_enrol">Enrollments</button>  
<div id="enrolModal"></div>

<script>
$(document).ready(function() {
//button modal
$('#btn_enrol').click(function(){
//using ajax post
$.post('enrollments.php',function() {
$('#enrolModal').html(); //Fill DIV enrolModal with enrollments.php content
})
//Calling Modal
$('#myModal').modal('show');
})
})
//-------------
</script>


enrollments.php



<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>

</div>


Also, when I try to click on the button several times there are quick blinks on the browser window. Any help will be appreciated, thanks.










share|improve this question

























  • Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

    – charlietfl
    Nov 23 '18 at 2:28













  • In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

    – Randy Casburn
    Nov 23 '18 at 2:30











  • Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

    – Moses
    Nov 23 '18 at 2:56














0












0








0








Similar questions like this has been posted before but none solved my issue. I'm trying to get enrollments.php page to show as a modal popup within index.php page



index.php



<button class="sess_btn sess_btn1" id="btn_enrol">Enrollments</button>  
<div id="enrolModal"></div>

<script>
$(document).ready(function() {
//button modal
$('#btn_enrol').click(function(){
//using ajax post
$.post('enrollments.php',function() {
$('#enrolModal').html(); //Fill DIV enrolModal with enrollments.php content
})
//Calling Modal
$('#myModal').modal('show');
})
})
//-------------
</script>


enrollments.php



<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>

</div>


Also, when I try to click on the button several times there are quick blinks on the browser window. Any help will be appreciated, thanks.










share|improve this question
















Similar questions like this has been posted before but none solved my issue. I'm trying to get enrollments.php page to show as a modal popup within index.php page



index.php



<button class="sess_btn sess_btn1" id="btn_enrol">Enrollments</button>  
<div id="enrolModal"></div>

<script>
$(document).ready(function() {
//button modal
$('#btn_enrol').click(function(){
//using ajax post
$.post('enrollments.php',function() {
$('#enrolModal').html(); //Fill DIV enrolModal with enrollments.php content
})
//Calling Modal
$('#myModal').modal('show');
})
})
//-------------
</script>


enrollments.php



<!-- The Modal -->
<div id="myModal" class="modal">

<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>

</div>


Also, when I try to click on the button several times there are quick blinks on the browser window. Any help will be appreciated, thanks.







javascript php html ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 3:01







Moses

















asked Nov 23 '18 at 2:23









MosesMoses

117




117













  • Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

    – charlietfl
    Nov 23 '18 at 2:28













  • In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

    – Randy Casburn
    Nov 23 '18 at 2:30











  • Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

    – Moses
    Nov 23 '18 at 2:56



















  • Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

    – charlietfl
    Nov 23 '18 at 2:28













  • In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

    – Randy Casburn
    Nov 23 '18 at 2:30











  • Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

    – Moses
    Nov 23 '18 at 2:56

















Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

– charlietfl
Nov 23 '18 at 2:28







Using $.post callback incorrectly and using html() incorrectly. Start in the API docs $.post .... html() and look at examples

– charlietfl
Nov 23 '18 at 2:28















In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

– Randy Casburn
Nov 23 '18 at 2:30





In addition, read up on async nature of AJAX requests - make sure you wait for the result to arrive before you try to manipulate the DOM (turn it into a modal).

– Randy Casburn
Nov 23 '18 at 2:30













Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

– Moses
Nov 23 '18 at 2:56





Close but not exactly what I'm in search for, some code example would have been quite helpful as I'm a newby with AJAX.

– Moses
Nov 23 '18 at 2:56












2 Answers
2






active

oldest

votes


















0














Did the corrections in code to use the jquery API correctly. Not tested but, below code will work.



<script>
$(document).ready(function() {
//button modal
$('#btn_enrol').click(function(){

$.post( "enrollments.php", function( htmlContents ) {
$('#enrolModal').html( htmlContents );

//Show the Modal once you get enrollments.php html contents
$('#myModal').modal('show');
});
})
})
//-------------
</script>





share|improve this answer































    0














    Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.



    index.html



    <script>
    $(document).ready(function() {
    $('.li-modal').on('click', function(e){
    e.preventDefault();
    $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
    })
    });
    </script>

    <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>

    <div class="modal fade text-center" id="theModal">
    <div class="modal-dialog">
    <div class="modal-content">
    </div>
    </div>
    </div>


    enrollments.php



    <script>
    // Get the modal
    var modal = document.getElementById('theModal');

    // Get the <span> element that closes the modal
    var span = document.getElementsByClassName("close")[0];

    // When the user clicks on <span> (x), close the modal
    span.onclick = function() {
    modal.style.display = "none";
    window.location.href = "updatesession.php";
    }

    // When the user clicks anywhere outside of the modal, close it
    window.onclick = function(event) {
    if (event.target == modal) {
    modal.style.display = "none";
    window.location.href = "updatesession.php";
    }
    }
    </script>

    <div id="model-content">
    <div class="modal-header">
    <span id="close" class="close">&times;</span>
    <p>Session Editor</p>
    </div>
    <div class="modal-body">
    <p>Select Session: </p>
    </div>
    <div class="modal-footer">
    <p>Modal Footer</p>
    </div>
    </div>





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439950%2fshow-modal-content-from-another-page-within-same-pages-popup%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Did the corrections in code to use the jquery API correctly. Not tested but, below code will work.



      <script>
      $(document).ready(function() {
      //button modal
      $('#btn_enrol').click(function(){

      $.post( "enrollments.php", function( htmlContents ) {
      $('#enrolModal').html( htmlContents );

      //Show the Modal once you get enrollments.php html contents
      $('#myModal').modal('show');
      });
      })
      })
      //-------------
      </script>





      share|improve this answer




























        0














        Did the corrections in code to use the jquery API correctly. Not tested but, below code will work.



        <script>
        $(document).ready(function() {
        //button modal
        $('#btn_enrol').click(function(){

        $.post( "enrollments.php", function( htmlContents ) {
        $('#enrolModal').html( htmlContents );

        //Show the Modal once you get enrollments.php html contents
        $('#myModal').modal('show');
        });
        })
        })
        //-------------
        </script>





        share|improve this answer


























          0












          0








          0







          Did the corrections in code to use the jquery API correctly. Not tested but, below code will work.



          <script>
          $(document).ready(function() {
          //button modal
          $('#btn_enrol').click(function(){

          $.post( "enrollments.php", function( htmlContents ) {
          $('#enrolModal').html( htmlContents );

          //Show the Modal once you get enrollments.php html contents
          $('#myModal').modal('show');
          });
          })
          })
          //-------------
          </script>





          share|improve this answer













          Did the corrections in code to use the jquery API correctly. Not tested but, below code will work.



          <script>
          $(document).ready(function() {
          //button modal
          $('#btn_enrol').click(function(){

          $.post( "enrollments.php", function( htmlContents ) {
          $('#enrolModal').html( htmlContents );

          //Show the Modal once you get enrollments.php html contents
          $('#myModal').modal('show');
          });
          })
          })
          //-------------
          </script>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 5:15









          MukundMukund

          16816




          16816

























              0














              Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.



              index.html



              <script>
              $(document).ready(function() {
              $('.li-modal').on('click', function(e){
              e.preventDefault();
              $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
              })
              });
              </script>

              <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>

              <div class="modal fade text-center" id="theModal">
              <div class="modal-dialog">
              <div class="modal-content">
              </div>
              </div>
              </div>


              enrollments.php



              <script>
              // Get the modal
              var modal = document.getElementById('theModal');

              // Get the <span> element that closes the modal
              var span = document.getElementsByClassName("close")[0];

              // When the user clicks on <span> (x), close the modal
              span.onclick = function() {
              modal.style.display = "none";
              window.location.href = "updatesession.php";
              }

              // When the user clicks anywhere outside of the modal, close it
              window.onclick = function(event) {
              if (event.target == modal) {
              modal.style.display = "none";
              window.location.href = "updatesession.php";
              }
              }
              </script>

              <div id="model-content">
              <div class="modal-header">
              <span id="close" class="close">&times;</span>
              <p>Session Editor</p>
              </div>
              <div class="modal-body">
              <p>Select Session: </p>
              </div>
              <div class="modal-footer">
              <p>Modal Footer</p>
              </div>
              </div>





              share|improve this answer






























                0














                Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.



                index.html



                <script>
                $(document).ready(function() {
                $('.li-modal').on('click', function(e){
                e.preventDefault();
                $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
                })
                });
                </script>

                <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>

                <div class="modal fade text-center" id="theModal">
                <div class="modal-dialog">
                <div class="modal-content">
                </div>
                </div>
                </div>


                enrollments.php



                <script>
                // Get the modal
                var modal = document.getElementById('theModal');

                // Get the <span> element that closes the modal
                var span = document.getElementsByClassName("close")[0];

                // When the user clicks on <span> (x), close the modal
                span.onclick = function() {
                modal.style.display = "none";
                window.location.href = "updatesession.php";
                }

                // When the user clicks anywhere outside of the modal, close it
                window.onclick = function(event) {
                if (event.target == modal) {
                modal.style.display = "none";
                window.location.href = "updatesession.php";
                }
                }
                </script>

                <div id="model-content">
                <div class="modal-header">
                <span id="close" class="close">&times;</span>
                <p>Session Editor</p>
                </div>
                <div class="modal-body">
                <p>Select Session: </p>
                </div>
                <div class="modal-footer">
                <p>Modal Footer</p>
                </div>
                </div>





                share|improve this answer




























                  0












                  0








                  0







                  Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.



                  index.html



                  <script>
                  $(document).ready(function() {
                  $('.li-modal').on('click', function(e){
                  e.preventDefault();
                  $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
                  })
                  });
                  </script>

                  <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>

                  <div class="modal fade text-center" id="theModal">
                  <div class="modal-dialog">
                  <div class="modal-content">
                  </div>
                  </div>
                  </div>


                  enrollments.php



                  <script>
                  // Get the modal
                  var modal = document.getElementById('theModal');

                  // Get the <span> element that closes the modal
                  var span = document.getElementsByClassName("close")[0];

                  // When the user clicks on <span> (x), close the modal
                  span.onclick = function() {
                  modal.style.display = "none";
                  window.location.href = "updatesession.php";
                  }

                  // When the user clicks anywhere outside of the modal, close it
                  window.onclick = function(event) {
                  if (event.target == modal) {
                  modal.style.display = "none";
                  window.location.href = "updatesession.php";
                  }
                  }
                  </script>

                  <div id="model-content">
                  <div class="modal-header">
                  <span id="close" class="close">&times;</span>
                  <p>Session Editor</p>
                  </div>
                  <div class="modal-body">
                  <p>Select Session: </p>
                  </div>
                  <div class="modal-footer">
                  <p>Modal Footer</p>
                  </div>
                  </div>





                  share|improve this answer















                  Thanks for the answer, I got it done a little differently. Instead of a button I used a link as shown.



                  index.html



                  <script>
                  $(document).ready(function() {
                  $('.li-modal').on('click', function(e){
                  e.preventDefault();
                  $('#theModal').modal('show').find('.modal-content').load($(this).attr('href'));
                  })
                  });
                  </script>

                  <a href="enrollments.php" class="li-modal" id="enrol_link" onMouseOver="this.style.background='rgb(0,66,79)'" onMouseOut="this.style.background='#4CAF50'">Enrollments</a>

                  <div class="modal fade text-center" id="theModal">
                  <div class="modal-dialog">
                  <div class="modal-content">
                  </div>
                  </div>
                  </div>


                  enrollments.php



                  <script>
                  // Get the modal
                  var modal = document.getElementById('theModal');

                  // Get the <span> element that closes the modal
                  var span = document.getElementsByClassName("close")[0];

                  // When the user clicks on <span> (x), close the modal
                  span.onclick = function() {
                  modal.style.display = "none";
                  window.location.href = "updatesession.php";
                  }

                  // When the user clicks anywhere outside of the modal, close it
                  window.onclick = function(event) {
                  if (event.target == modal) {
                  modal.style.display = "none";
                  window.location.href = "updatesession.php";
                  }
                  }
                  </script>

                  <div id="model-content">
                  <div class="modal-header">
                  <span id="close" class="close">&times;</span>
                  <p>Session Editor</p>
                  </div>
                  <div class="modal-body">
                  <p>Select Session: </p>
                  </div>
                  <div class="modal-footer">
                  <p>Modal Footer</p>
                  </div>
                  </div>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 26 '18 at 3:00

























                  answered Nov 25 '18 at 22:59









                  MosesMoses

                  117




                  117






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439950%2fshow-modal-content-from-another-page-within-same-pages-popup%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin