weixin_33744854 2016-02-23 16:14 采纳率: 0%
浏览 16

重用Ajax调用作为函数

Having a bit of an issue with AJAX. Im setting up this function:

<script>
    function popEvents(){
    var $sqlcal = $('#calHeader').data('sqlcal');
    console.log($sqlcal);
    $.ajax({
        type: "GET",
        url: 'XXXX.php',
        data: {sqlcal: $sqlcal},
        dataType: 'json',
        cache: false,

        success: function(data){



            var x = data;
            console.log(x);
            $('.open-button').each(function(){
                var e = $(this);
                var e1 = e.data('dtc');

                if (($.inArray(e1, x) > -1)){
                    e.css('background','red');
                    console.log('yes')
                }else{
                    console.log('no');
                    }

            });

        },
        error: function(){
            console.log('didnt work');
        }

    });
    delete $sqlcal;




    }
</script>

to run when the page loads(this will populate events based on calendar dates) and it works fine. Now on the same page, there is a dropdown button on the calendar to select a different calendar.

GOAL

If a user clicks on a different calendar, the current events disappear(right now just css background color) and the new events get populated in using the function popEvents.

Issue

Here is my code for the li options:

<script>

   $( document.body ).on( 'click', '.dropdown-menu li a', function( event ) {

      var $target = $( event.currentTarget );
      var $value = $(this).data('value');


      $target.closest( '.widget-header' )
         .find( '#calHeader' ).text( $target.text() ).attr('data-sqlCal',$value)
            .end()
         .children( '.dropdown-toggle' ).dropdown( 'toggle' );
        popEvents();
      return false;

   });

</script>

When the user selects a new calendar, the 'data-sqlcal' does update but the ajax call in console log does not update with the new value of 'data-sqlcal' but rather makes the same call that it did when the page loads. Can someone help me with this and explain why this is happening? Thanks for the help in advance

console.log output when page loads and user changes calendar:

conferenceevents \\ default calendar on page 
xxxxx.php:579 ["2016-02-05", "2016-02-05", "2016-02-05", "2016-02-06", "2016-02-07"]
xxxxx.php:588 no
xxxxxx.php:586 yes
xxxxxxx:588 no
VM24700:3 XHR Loaded (xxxxxx.php - 200 OK - 24.323000106960535ms - 289B)

//clicked on a new calendar from dropdown

xxxxx.php:566 conferenceevents \\ Didnt update(should be huddleoneevents)
xxxxxx.php:579 ["2016-02-05", "2016-02-05", "2016-02-05", "2016-02-06", "2016-02-07"]
xxxxxx.php:588 no
xxxxxx.php:586 yes
xxxxxxxxx.php:588 no
VM24705:3 XHR Loaded (xxxxx.php - 200 OK - 7.968999911099672ms - 290B)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置