如何从javascript的URL中检索html文档?

时间:2010-02-10 06:22:29

标签: jquery dom post httpwebrequest get

我有一个网址,我想检索在javascript变量中转到url(页面的所有代码)时生成的html dom。

我该怎么做?我猜一个HTML获取或发布?任何人都可以举例说明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");

每个调用中的第一个警报显示为空白,第二个警报显示为空。有什么想法吗?

谢谢,
马特

2 个答案:

答案 0 :(得分:0)

由于same origin policy,您只能从自己的域中获取文档(以这种方式)。

答案 1 :(得分:0)

$( “#DIVID”)负载( “documentname.html”);