有關ajax跨域捉屏的問題

edited 十月 2013 in Javascript
先看看代碼
function createXHR()
{
try { return new XMLHttpRequest(); } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}

return null;
}


function sendRequest()
{
var url = "http://ccuuttww.freeinternet.cc";
var xhr = createXHR();
if (xhr)
{
xhr.open("HEAD", url, true);
xhr.onreadystatechange = function(){handleResponse(xhr);};
xhr.send(null);
}
}

function handleResponse(xhr)
{
if (xhr.readyState == 4 && xhr.status == 200)
{
alert(xhr.responseText);
}
}
sendRequest();
結果連接是成功的(目標頁面非本地)但xhr.status永遠都不會200回來的xhrtext一定是空,這是代碼的問題還是同源限制???

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=6254

評論

Sign In or Register to comment.