需要帮助来使用javascript或jquery来获取bodycontent

时间:2021-09-01 02:04:22

I have page i want replace body content with some second page body content.From the second page response text how to i will get the body content to replace the existing body content.

我有页面我希望用一些第二页主体内容替换正文内容。从第二页响应文本如何获取正文内容来替换现有的正文内容。

please help to me do this.

请帮帮我这样做。

Thanks , In advance, Raja.

谢谢,提前,拉贾。

5 个解决方案

#1


1  

jQuery's load() function will do the trick:

jQuery的load()函数可以解决这个问题:

$(function(){
    $("#something").load("/path/to/page2.php body");
});

Where #something is a jQuery selector of the element you want the data to load into, /path/to/page2.php is a relative URL to the page you want to load and body is the element on the page you want to load into the element. Information on how to use the function is available from load at jQuery API.

其中#something是要加载数据的元素的jQuery选择器,/ path / to / page2.php是要加载的页面的相对URL,body是要加载到的页面上的元素元素。有关如何使用该函数的信息可从jQuery API的load中获得。

Ad@m

广告@米

#2


0  

$(body)[0]

But why are you doing this, rather than just replacing the content ( in a div with a class )

但是你为什么要这样做,而不是仅仅替换内容(在一个div的类中)

#3


0  

I am not sure if I understood you well, but if all you are trying to do is to set a page body element with the response you have got from ajax, then that should work:

我不确定我是否理解你,但是如果你要做的就是设置一个页面体元素和你从ajax得到的响应,那么这应该有效:

document.body.innerHTML = ajaxRequest.responseText;

#4


0  

Well with jquery you could do something like this:

那么使用jquery你可以做这样的事情:

  $('body').load('otherpage.html body');

This would clear the body of your html and load the body from otherpage.html

这将清除你的html的主体并从otherpage.html加载正文

#5


0  

$('body').html('your new content goes here')

#1


1  

jQuery's load() function will do the trick:

jQuery的load()函数可以解决这个问题:

$(function(){
    $("#something").load("/path/to/page2.php body");
});

Where #something is a jQuery selector of the element you want the data to load into, /path/to/page2.php is a relative URL to the page you want to load and body is the element on the page you want to load into the element. Information on how to use the function is available from load at jQuery API.

其中#something是要加载数据的元素的jQuery选择器,/ path / to / page2.php是要加载的页面的相对URL,body是要加载到的页面上的元素元素。有关如何使用该函数的信息可从jQuery API的load中获得。

Ad@m

广告@米

#2


0  

$(body)[0]

But why are you doing this, rather than just replacing the content ( in a div with a class )

但是你为什么要这样做,而不是仅仅替换内容(在一个div的类中)

#3


0  

I am not sure if I understood you well, but if all you are trying to do is to set a page body element with the response you have got from ajax, then that should work:

我不确定我是否理解你,但是如果你要做的就是设置一个页面体元素和你从ajax得到的响应,那么这应该有效:

document.body.innerHTML = ajaxRequest.responseText;

#4


0  

Well with jquery you could do something like this:

那么使用jquery你可以做这样的事情:

  $('body').load('otherpage.html body');

This would clear the body of your html and load the body from otherpage.html

这将清除你的html的主体并从otherpage.html加载正文

#5


0  

$('body').html('your new content goes here')