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