Php 如何将网站源代码作为原始文本Jquery

Php 如何将网站源代码作为原始文本Jquery,php,javascript,jquery,html,Php,Javascript,Jquery,Html,我一直在到处搜索,但似乎找不到答案,我想用原始文本检索网站的源代码,我尝试了一些方法,如 $("#divname").html('<object data="http://example.com/">'); $(“#divname”).html(“”); 但你得到的只是一个加载了网站的div,如果我将其更改为.text或.val,它将无法工作:/ 使用或将非常感谢任何帮助 您可以在php中使用curl(编写简单代理)并调用ajax从url获取页面 file.php: if

我一直在到处搜索,但似乎找不到答案,我想用原始文本检索网站的源代码,我尝试了一些方法,如

    $("#divname").html('<object data="http://example.com/">');
$(“#divname”).html(“”);
但你得到的只是一个加载了网站的div,如果我将其更改为.text或.val,它将无法工作:/

使用或将非常感谢任何帮助

您可以在php中使用curl(编写简单代理)并调用ajax从url获取页面

file.php

if (isset($_POST['url'])) {
    $ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $_POST['url']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    echo curl_exec($ch);
}
在javascript中使用ajax

$.ajax({
    url: 'file.php',
    type: 'POST',
    data: {url: 'http://example.com/'},
    dataType: 'text',
    success: function(html) {
       // process html
    }
});

我使用
$.ajax
函数是因为
$.post
会将内容解析为html而不是文本。

你想要网站的源代码(与JS代码所在的域相同),还是想要其他网站的源代码?他特别提到jquery,你为什么要使用PHP!?
$.ajax({
    url: 'file.php',
    type: 'POST',
    data: {url: 'http://example.com/'},
    dataType: 'text',
    success: function(html) {
       // process html
    }
});