开发者

Dynamic parameters for dynamic contents with qTip

开发者 https://www.devze.com 2022-12-20 13:23 出处:网络
I want to pass a dynamic parameter with qTip, but it fails. my_ajax_controller.php just displays the variable type, but not q.

I want to pass a dynamic parameter with qTip, but it fails. my_ajax_controller.php just displays the variable type, but not q.

$('a.menu_help').qtip({
    content: {
      url:'my_ajax_controller.php',
   开发者_运维技巧   data: 'type=help_menu&q='+$(this).attr('id'),
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
});

However, a static value of q works:

$('a.menu_help').qtip({
    content: {
      url:'my_ajax_controller.php',
      data: 'type=help_menu&q=toto',
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
});

Is there no way to pass a dynamic value to the parameter data ?

Thanks in advance !

Florent


try something like this:

$('a.menu_help').each(function(){
    $currentLink = $(this);
    $currentLink.qtip({
        content: {
          url:'my_ajax_controller.php',
          data: 'type=help_menu&q='+$currentLink.attr('id'),
          method: 'get'
        },
        show: 'mouseover',
        hide: 'mouseout'
});

I haven't tested this, but i've done something similar. Just can't find it right now.


I had the same problem and i solved with this code. Works fine with qtip 1.0 rc3 and JQuery 1.4.2. Note that qtip has and issue with jquery>1.3. Google for related info, but it's easy to fix adding a single line on jquery.qtip.js

$('.username_link').each(function(){
   $(this).click(function(){ return false });//JS enabled => link default behavior disabled. Gaceful degradation
   $(this).qtip({
   content: { url: '/users/links',
              data: { id: $(this).attr('data-id') },
              method: 'post'
            },
   show: 'click',
   hide: 'mouseout'
   })
});


It should work, but just try to see what you pass as ID, or pass data as collection something like:

data : {'type':'help_menu', 'q':id}

Or

   
 $('a.menu_help').qtip({
    var id = $(this).attr('id');
    alert(id);
    content: {
      url:'my_ajax_controller.php',
      data: 'type=help_menu&q='+ id,
      method: 'get'
    },
    show: 'mouseover',
    hide: 'mouseout'
});
0

精彩评论

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