有没有JavaScript方法来做file_get_contents()? [英] Is there a JavaScript way to do file_get_contents()?

查看:124
本文介绍了有没有JavaScript方法来做file_get_contents()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 PHP文档

以下是我在Ajax调用中使用它的方法,如果我找不到纯客户端方式来执行此操作。

Here is how I would use it in an Ajax call, if I don't find a pure client way to do this.

$homepage = file_get_contents('http://www.example.com/');
echo $homepage;

有没有办法做这个客户端,所以我没有ajax字符串结束?

Is there way to do this client side instead so I don't have to ajax the string over?

推荐答案

你能做什么

JS代码:

$.post('phppage.php', { url: url }, function(data) {
    document.getElementById('somediv').innerHTML = data;        
});

PHP代码:

$url = $_POST['url'];
echo file_get_contents($url);

这样可以获得网址的内容。

That would get you the contents of the url.

这篇关于有没有JavaScript方法来做file_get_contents()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆