【问题标题】:Send post with jquery and load a specific selector使用 jquery 发送帖子并加载特定的选择器
【发布时间】:2012-11-21 09:25:54
【问题描述】:

我想用 Jquery $.POST() 发布一个表单值并加载一个特定的选择器 我不知道怎么做可能是用 json 或类似的东西

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

我只想加载标题和描述而不是整个页面

我想在灯箱中检索此标题和描述,我该怎么做?

【问题讨论】:

  • topic.php 上的哪些元素包含标题和描述?那些标签来自页面的<head>
  • JSON 听起来很酷,它会正常工作。它通过用户友好而轻巧,易于解析和操作。

标签: php jquery json post


【解决方案1】:

也许这会有所帮助:

$.post('topic.php', {id: id}, function(data){
    $("#message").html($(data).find("#your_dom_selector"));
    ...
}

【讨论】:

  • 这个解决方案对我来说似乎是糟糕的设计。你只是给了这个人一条鱼,而你应该教他如何钓鱼。国际海事组织。
  • 好吧,我不想详细介绍这个简单的问题,所以我认为显示一行代码比关于制定解决方案的句子要好。另外,如果您能指出糟糕的设计是什么意思,我将不胜感激?
  • 如果你能教我如何钓鱼他,我将不胜感激:D
  • 好的,如果我想在灯箱中检索此标题和描述,我该怎么做?
  • 如果您使用 jquery 的灯箱插件,那么我认为这应该可以解决问题: $(data).find('title').lightbox( /* {your_options} */ );
【解决方案2】:
$.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;
});​

【讨论】:

    猜你喜欢
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    相关资源
    最近更新 更多