views:

514

answers:

2

I have a partial view with a dropdown (with Paid and unpaid as options) and a button. I am loading this partial view using jquery load, when the user click Paid/Unpaid List link in the sub menu of a page.

When i select Paid in dropdown and click the button, it shows the list of paid customers in the jquery dialog and if i select Unpaid and click button, it shows unpaid customers in the jquery dialog.

I am writing the following code for the dialog:

 $('#customers').dialog({
            bgiframe: true,
            autoOpen: false,
            open: function(event, ui) {
                //populate table
                var p_option = $('#d_PaidUnPaid option:selected').val();
                if (p_option  == 'PAID') {
                    $("#customercontent").html('');
                    //$("#customercontent").load("/Customer/Paid");
                }
                else if (p_option  == 'UNPAID') {
                    $("#customercontent").html('');
                    //$("#customercontent").load("/Customer/Unpaid");
                }
            },
            close: function(event, ui) {
                //do nothing
            },
            height: 500,
            width: 550,
            modal: true
        });

For the first time, i am getting the list correctly in the jquery dialog, but when i click the Paid/Unpaid List link again and select Unpaid in the dropdown and click the button, it shows the previos loaded content in the jquery dialog.

What am i doing wrong here?

+2  A: 

Try adding no-caching option to jQuery AJAX. I had problems with the load() function (and IE) where cached results would always be shown. To change the setting for all jQuery AJAX requests do

$.ajaxSetup({cache: false});
Marek Karbarz
where should i need to add this line? before loading the partial view? –
Prasad
even right before $('#customers').dialog({... should suffice. If you have any type of javascript bootstrap file, that's where it would normally go
Marek Karbarz
i have called in the click event of the button before opening dialog, but still the problem occurs
Prasad
Here is the click event of the button added in $(document).ready: $('#b_customers').click(function(e) { $.ajaxSetup({ cache: false }); $('#customers').dialog('open'); });
Prasad
A: 

Try add this after open:

$('#customers').empty().remove();

Example:

    open: function(event, ui) {
              //populate table
              var p_option = $('#d_PaidUnPaid option:selected').val();
              if (p_option  == 'PAID') {
                  $("#customercontent").html('');
                  //$("#customercontent").load("/Customer/Paid");
              }
              else if (p_option  == 'UNPAID') {
                  $("#customercontent").html('');
                  //$("#customercontent").load("/Customer/Unpaid");
              }

              $('#customers').empty().remove();

          },
Saimer