Web サイトの html を取得してリンクをチェックしたいので、次の ajax コードを使用してリモート Web サイトの html を取得します。
$.ajax({
type : 'get',
url : 'proxy.php',
dataType : 'html',
success : function(data){
alert('success');
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert('error');
}
});
proxy.php は、サーバー上にないため、データを取得するために使用するプロキシです。
<?php
// Set your return content type
header('Content-type: application/html');
// Website url to open
$daurl = 'http://example.com';
// Get that website's content
$handle = fopen($daurl, "r");
// If there is something, read and return
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
コードは常にエラーを警告しますが、私は ajax の専門家ではないため、すべてが問題ないことを理解できません。それは間違ったajaxデータ型ですか?プロキシファイルのヘッダーが間違っていますか???