开发者

accessing Session variable from jquery , expanding/collapsing submenu

开发者 https://www.devze.com 2023-04-04 20:32 出处:网络
I\'m trying to access a Session Variable from jquery to expand/collapse a submenu based on the ul index (using eq)

I'm trying to access a Session Variable from jquery to expand/collapse a submenu based on the ul index (using eq)

function initMenu() {
  $('#menu ul').hide();

  $('#menu ul:eq('**<%Session["Menu"]%>**')').show();

  $('#menu li a').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        return 开发者_JAVA技巧false;
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
        $('#menu ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
$(document).ready(function() {initMenu();});

using $('#menu ul:eq(0)').show();

This works perfectly, but I cannot get it to work using the session variable


Try this instead:

<%= Session["Menu"] %>


you are not writing the session value to the page try

$('#menu ul:eq('<%:Session["Menu"]%>')').show();


Well you'll need to make an ajax call to return the session value you're looking for...

Something along this lines

var html = $.ajax({
            type: "POST",
            url: "path to the file&act=something",
            async: false
        }).responseText;

In your file you should check for act=somethinhg and return the session value

responseText should now have your session value

0

精彩评论

暂无评论...
验证码 换一张
取 消