English 中文(简体)
我怎样使用javascript从一个url中检索html文档?
原标题:how can I retrieve an html document from a url from javascript?

我有一个网址,我想在Javascript变量中检索访问该网址时生成的HTML DOM(页面的所有代码)。

我该如何做到这一点?我猜测是使用HTML的get或post?有人可以用jQuery给个例子吗?

每次我这样做一个$.get或$.post:

$.get("http://www.google.ca", function(result) { alert(result); alert($(result).html()); });

$.post("http://www.google.ca", function(result) { alert(result); alert($(result).html()); }, "xml");

每个电话中的第一个警报出现空白,第二个警报出现为null。有什么想法?

Thanks,
Matt

最佳回答

由于同源策略,您只能从自己的域中提取文档(以此方式)。

问题回答

$("#divId").load("documentname.html"); $("#divId").load("documentname.html");





相关问题
PHP DOM - accessing newly added nodes

I use the following to get a html document into DOM: $dom = new domDocument( 1.0 , utf-8 ); $dom->loadHTML($html) and then I add some new content to an element in the html: $element = $dom->...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签