如何从javascript的url检索html文档? [英] how can I retrieve an html document from a url from javascript?
本文介绍了如何从javascript的url检索html文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个url,我想要检索一个javascript变量中url(页面的所有代码)时生成的html dom。
I have a url and I want to retrieve the html dom generated when going to the url (all the code for the page) in a javascript variable.
我可以这样做吗我猜想一个html获取或发布?任何人都可以提供一个jQuery的例子?
How can I do this? I'm guessing an html get or post? Can anyone give an example with jQuery?
每次我这样做一个$ .get或$ .post:
Every time I do a $.get or $.post like this:
$.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");
每个调用中的第一个警报都显示为空白,第二个提示为空。任何想法?
the first alert in each call comes up blank and the second comes up as null. Any ideas?
谢谢,
Matt
Thanks,
Matt
推荐答案
由于相同的起源政策,您只能以这种方式从您自己的域中获取文档。
这篇关于如何从javascript的url检索html文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文