我想用JavaScript處理http請求的響應。你可以在這裏找到一個簡單的例子。http-Get request with empty response
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title>JavaScript Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function serviceCall() {
$.ajax({
type: "GET",
url: 'http://localhost:8181/geoserver/wfs?Service=WFS&Request=GetFeature&Version=1.0.0&typename=topp:tasmania_water_bodies&SRS=EPSG:4326',
// url: 'http://demo.opengeo.org/geoserver/ows?Service=WFS&Request=GetFeature&Version=1.0.0&typename=topp:tasmania_water_bodies&SRS=EPSG:4326',
complete: function(xml, status){
alert(xml.responseText);
}
});
}
</script>
</head>
<body>
<center><button onclick="serviceCall()">Start...</button></center>
</body>
</html>
該請求直接在瀏覽器中運行。通過Ajax和JavaScript,響應是空的。 Firebug在第1行第1列報告了xml解析錯誤。我嘗試將請求發送到本地主機和遠程服務器,但響應始終爲空。我將不勝感激任何建議。
您對響應內容有什麼期待? – GreenRover
http://en.wikipedia.org/wiki/Same_origin_policy – ManseUK
你爲什麼要處理完成而不是ajax的成功事件? – ryadavilli