【问题标题】:JavaScript's equivalent to file_get_contents [duplicate]JavaScript 等效于 file_get_contents [重复]
【发布时间】:2018-02-07 05:58:07
【问题描述】:

在 PHP 中,我们有一个名为 file_get_contents 的函数,它可以获取网站的内容并将其转换为字符串,但是 JavaScript 呢? JavaScript 与 file_get_contents 的等价物是什么?有吗?

$string = file_get_contents("http://example.com/");

我无法访问 PHP,我正在使用 Tampermonkey 编辑此代码,所以它只是 JavaScript。

【问题讨论】:

  • 您正在寻找 AJAX。
  • @gforce301 我无权访问 PHP,我仅在 Tampermonkey 上使用此代码,因此严格来说只是 JavaScript。

标签: javascript file-get-contents tampermonkey


【解决方案1】:

对于节点,有http.get()

对于现代浏览器,有fetch()

对于旧版浏览器,有XHR

【讨论】:

    猜你喜欢
    • 2012-02-05
    • 2014-10-20
    • 2013-10-01
    • 1970-01-01
    • 2013-05-02
    • 2014-06-20
    • 2021-12-20
    • 1970-01-01
    • 2018-12-19
    相关资源
    最近更新 更多