如果我有一個從遠程服務器調用php文件但php文件不可用的代碼,如何添加消息「服務器不可用」?這裏是我的代碼:服務器不可用
<html>
<head>
<script language="Javascript">
function View(){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("datatable").innerHTML=xmlhttp.responseText;
}
xmlhttp.open("POST", "http://someremoteserver/somephpfile.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
}
</script>
</head>
<body onload="View();" >
<div id="datatable" align="center"></div>
</body>
</html>
http://en.wikipedia.org/wiki/Same_origin_policy –
你爲什麼標記「jQuery的」當你不使用jquery ? 在jQuery中,您可以使用jsonp數據類型進行跨域請求。 回調「失敗」有3個參數。有一個你可以得到http狀態(503服務不可用)。 – PKeidel