JQuery.load Method that causes an AJAX page to refresh

I have a functional JSP page that accepts URL parameters and updates the table on the page with information based on these parameters.

I have a set of different tabs that pass the specified paranoia URLs to the page on which they are located, so it reloads and displays this new data.

I am trying to use the jQuery.load and .ajax methods so that I can pass these URL parameters to a page on the server and then only serve the table via AJAX, and not update the whole page.

The problem is that sometimes the page refreshes, and I cannot understand why this is happening.

Here is jQuery:

$('ul#coverTabs > li').live('click', function() {       

    // Removes default class applied in HTML and onClick adds 'currentTab' class
    $(".currentTab").removeClass("currentTab");
    $(this).addClass("currentTab"); 

    // Find href of current tab
    var $tabValue = $('ul#coverTabs > li.currentTab > a').attr('href');

    // Load new table based on href URL variables   
    $('#benefit').load($tabValue + ' #' + 'benefit');

    /*$.ajax({ 
      cache: false,
      dataType: "html",
      url: $tabValue, 
      success: function(data) { 
         //var $tableWrap = $('#benefit'); 

         //$('.benefitWrap').append($('.benefitWrap'));

         //alert($tableWrap);
      },
    });*/


    return false;       

});

Here is the HTML for the tabs:

<ul id="coverTabs">
    <li class="currentTab"><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&amp;productPolicyId=748#a1">Individual</a></li>
    <li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&amp;productPolicyId=749#a1">Couple</a></li>
    <li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&amp;productPolicyId=750#a1">Family</a></li>
    <li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&amp;productPolicyId=751#a1">Single Parent Family</a></li>
</ul>
+3
2

false, li, , a li. , :

$('ul#coverTabs > li > a').click(function(event) {   
    event.preventDefault(); 
}
+7

( url):

<script>
$("a").click(function(event) {
  event.preventDefault();
  // your actions
});
</script>

, , , URL- HREF.

+3

Source: https://habr.com/ru/post/1734069/


All Articles