I have a functional JSP page that accepts URL parameters and updates a table on the page with info based on those parameters.
I have a set of different tabs which pass said URL paraneters to the page they are on so it then re-loads and displays this new data.
I have been trying to use jQuery .load and .ajax methods so that i can pass these URL parameters to the page on the server and then only serve up the table via AJAX rather than doing a whole page refresh.
The problem i am having is that sometimes the page does refresh and i cannot work out why this is happening.
Here is the 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&productPolicyId=748#a1">Individual</a></li>
<li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=749#a1">Couple</a></li>
<li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=750#a1">Family</a></li>
<li><a href="quoteAction.do?getBenefitLevelDetails=getBenefitLevelDetails&productPolicyId=751#a1">Single Parent Family</a></li>
</ul>
You are returning false when the user clicks on the
lielement, which doesn’t do anything to prevent theaelement within thelielement from firing. You need to override their default action to prevent them from firing: