1

I am having slider for a set of data with paging, the problem is that the div containing the slider is loaded from ajax request via ajax. so it's not working.

paging function:

function loadData(page){
                    loading_show();
                    confID = $("#confID").val();
                    verID = $("#confID").attr("v");
                    $.ajax
                    ({
                        type: "POST",
                        url: "paging-offlineTemp.php",
                        data: {page:page, confID: confID, verID:verID},
                        success: function(msg)
                        {
                                loading_hide();
                                $("#container").html(msg);
                                resize_iframe();
                                $(".slider").each(function(){
                                    $(this).slider({ animate: true,
                                        value: parseInt($(this).attr("preRate")),
                                        min: 0,
                                        max: 5,
                                        step: 1
                                    });
                                    if($(this).attr("preRate") == -1) {
                                        $(this).slider({ disabled: true }); 
                                        td = $(this).parent("td");
                                        tr = $(td).parent("tr");
                                        box= $(tr).find(":checkbox");
                                        $(box).attr("checked",true);

                                    }   
                                });
                        }
                    });
                }

pageing-offlineTemp.php is too long but it just select the next set of data by limit

function which control slider:

$(".slider").each(function(){
                    $(this).slider({ animate: true,
                        value: parseInt($(this).attr("preRate")),
                        min: 0,
                        max: 5,
                        step: 1,
                        change: function( event, ui ) {
                            $(this).attr("rate", ui.value);
                            rate = $(this).attr("rate");
                            confID = $(this).attr("confID");
                            critID = $(this).attr("criteria");
                            paperID = $(this).attr("paperID");
                            label = $(this).parent("td").find("label");
                            $(label).html("New rate: "+ rate);
                            td = $(this).parent("td");
                            tr = $(td).parent("tr");
                            span = $(tr).find("span");
                            $(span).fadeIn("slow");
                            $.ajax ({
                                data:{rate:rate, confID:confID, critID:critID, paperID:paperID},
                                type: 'POST',
                                url:  'update_rate.php',
                                success: function(response) {
                                    //alert(response)
                                    $(span).delay(500).fadeOut('slow');
                                }
                            });
                        } 
                    });

slider div:

<div type="" paperID="'. $paper .'" preRate="'. intval($irate) .'"
                                 criteria="'.$row['rate_id'].'" confID="'.$conf_id.'" rate="" class="slider">
                    </div>

I guess is that the slider function don't fire because initially the paging container div is empty and no element with class slider, So is there a work around to keep the paging while the slider event fire?

4

2 に答える 2

1

簡単な答え:$('.slider').each(の成功コールバックに移動しますajax function

于 2012-09-11T06:49:32.660 に答える
0

ajax呼び出しを同期させることが1つの解決策であるか、成功コールバック関数でスライダー関数を呼び出すことも機能します

于 2012-09-11T06:26:48.110 に答える