[英]Need help to get the bodycontent using javascript or jquery
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.谢谢,提前,拉贾。
jQuery's load()
function will do the trick: jQuery 的
load()
function 可以解决问题:
$(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.其中
#something
是您希望数据加载到的元素的 jQuery 选择器, /path/to/page2.php
to/page2.php 是相对的 URL 是您想要加载到页面body
的元素元素。 Information on how to use the function is available from load at jQuery API .有关如何使用 function 的信息可从jQuery API 下载。
Ad@m广告@m
$(body)[0]
But why are you doing this, rather than just replacing the content ( in a div with a class )但是你为什么要这样做,而不仅仅是替换内容(在一个带有 class 的 div 中)
$('body').html('your new content goes here')
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 的主体并从其他页面加载主体。html
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.