weixin_33713503 2012-04-22 05:28 采纳率: 0%
浏览 18

jQuery .get数据操作

I am using below code to get a page:

$.get('http://example.com/page1.html', function (data) {

});

Now lets imagine there is a #content div inside that page1.html and I need to read it's inner html as I already have #content div on page where Ajax call is occurring.

What is the right way to do this? I've tried with:

data = $(data).find('#content').html();
$("#content").empty().append(data);

But it seems that html() function is not the right one as it returns null, while contents() is returning data but I am not skillful enough to get only what I need from it.

Any help appreciated, thanks!!

  • 写回答

2条回答 默认 最新

  • weixin_33709364 2012-04-22 06:10
    关注

    this code

    data = $(data).find('#content').html();
    

    return null when data is

    var data ="<div id='content'>my data</div>";
    

    because #content already parent, if data is

    var data ="<div><div id='content'>my data</div><div>";
    

    then return exact html because this time #content is child and you can .find() this in parent div.

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试