dsns47611 2012-11-21 10:55
浏览 59
已采纳

使用jquery发送帖子并在“灯箱”中加载特定选择器

i want to Post a form value with Jquery $.POST() and load a specific selector i don't know how to do it may be with json or something like that

$.post('topic.php', {
    id: id
}, function(data) {
    $("#message")
        .html($(data).('attr', 'title'))
        .hide()
        .slideDown(500); //Fade in the data given by the topic.php file
});
return false;
});​

i just want to load the title and description not the whole page

i want to retrieve this title and description in a lightbox how can i do it?

  • 写回答

1条回答 默认 最新

  • duanba2001 2012-11-21 11:09
    关注

    First, jQuery (and even many browsers internally) sends a HTTP_X_REQUESTED_WITH header. You could catch it in topic.php and returns json instead of html. Check this link for an how-to: http://www.electrictoolbox.com/how-to-tell-ajax-request-php/

    If you really want to extract content from returned html, it's fairly simple: create a blank DOM object with jQuery, give it the HTML data, then retrieve whatever element you want with the find function:

    $.post('topic.php', {
        id: id
    }, function(data) {
    $("#message")
        .html($('<div></div>').html(data).find('a').('attr', 'title'))
        .hide()
        .slideDown(500); //Fade in the data given by the topic.php file
    });
    return false;
    });​
    

    Replace the 'a' tag in find function by any selector you need. A working example here: http://jsfiddle.net/GeX7d/

    EDIT: for the lightbox part, there are plenty of tutorials on the web that describe the process, this one will fit your needs: http://www.cssjockey.com/web-design-tutorials/an-easy-way-to-create-light-box-with-jquery-css

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多