--------------------webservice------------------------------------------------------
namespace Weather
{
/// <summary>
/// Service1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class Weather : System.Web.Services.WebService
{ [WebMethod]
public XmlDocument GetWeather(string city)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("D:/Weather/beijing.xml");
return xmldoc;
}
}
}
----------------------------------ajax代码-------------------------------------------------------<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
<![CDATA[
var xmlHttp;
function createXmlRequest()
{ var xmlHttp=new XMLHttpRequest();
return xmlHttp; }
function showMes(){
xmlHttp=createXmlRequest();
xmlHttp.onreadystatechange=handleStateChange;
alert(1)
xmlHttp.open("GET","http://210.77.146.22/Weather.asmx?city=北京",true); xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
var xmlDom=xmlHttp.responseXML;
alert(xmlHttp.responseXML)
text =document.createTextNode(xmlDom.getElementsByTagName("weatherInfo")[0].childNodes[0].childNodes[0].nodeValue)
document.getElementById("divMes").appendChild(text);
}
}
]]>
</script>
<body onload="showMes();">
<div>111111111111111111111</div>
<div id="divMes">asd</div>
</body>
</html>-----------------------请教-------------------------------------------------------
xmlhttp.responsexml为什么没有数据呢,是不是我访问webservice的写法有问题请指点~!谢谢
晕了,CSDN能回答问题的人越来越少了~!