在JavaScript中,有没有办法获取给定URL的源代码? [英] In JavaScript, is there a way to get source code of a given URL?
本文介绍了在JavaScript中,有没有办法获取给定URL的源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在JavaScript中,有没有办法在给定URL的情况下获取页面的源代码?等同于PHP的file_get_contents()
In JavaScript, is there a way to get source code of a page given its URL? Kind of equivalent to PHP's file_get_contents()
推荐答案
您可以通过XMLHttpRequest(或jQuery的 ajax
):
You can just download from a URL through XMLHttpRequest (or jQuery's ajax
):
$.get(
'yourfile.js',
function(data) {
// The source code is in data
}
);
这篇关于在JavaScript中,有没有办法获取给定URL的源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文