0
我希望得到一个网站的HTML来检查它的链接, 我用下面的Ajax代码来获得一个远程网站的HTML:Ajax和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);
}
?>
代码总是提醒错误,我无法理解的是一切都OK,因为我不是专家,阿贾克斯,所以我想任何人都可能检查我的?它是错误的ajax数据类型?代理文件中的头文件是否错误?
在你的误差函数试图提醒textStatus或errorThrown而不是字符串说错误,告诉我们是什么错误。 – piddl0r 2013-04-09 09:06:48
textStatus警报错误,但errorThrown警报未找到 – 2013-04-09 09:12:31
你检查了开发者控制台吗? – piddl0r 2013-04-09 09:30:29