js 调用WebService 火狐下无反应
<script language="javascript" type="text/javascript">
function RequestByPost(value) {
var xmlhttpps;
try {
xmlhttpps = new ActiveXObject("Msxml.XMLHTTP");
} catch (a) {
try {
xmlhttpps = new ActiveXObject("Microsoft.XMLHTTP");
} catch (a) {
xmlhttpps = false;
}
}
if (!xmlhttpps && typeof XmlHttpRequest != 'undefined') {
xmlhttpps = new XMLHttpRequest();
}
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
data = data + '<soap:Body>';
data = data + '<GetTime xmlns="http://tempuri.org/">';
data = data + '<input>' + value + '</input>';
data = data + '</GetTime>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
//var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
// xmlhttp = createXMLHttp();
// xmlHttpps = createXMLHttp;
alert(xmlhttpps);
var URL = "http://localhost/WebService/CityService.asmx";
xmlhttpps.open("POST", URL, false);
xmlhttpps.onreadystatechange = function () {
if (xmlhttpps.readyState == 4) {
if (xmlhttpps.status == 200) {
document.getElementById("TextArea1").value = xmlhttpps.responseText;
// alert(xmlhttpps.responseText);
}
}
};
xmlhttpps.SetRequestHeader("Content-Type", "text/xml; charset=gb2312");
xmlhttpps.SetRequestHeader("SOAPAction", "http://tempuri.org/GetTime");
xmlhttpps.send(data);
}
</Script>
<body>
<textarea id="TextArea1" name="S1" rows="10"></textarea>
<input type="button" value="CallWebserviceByPost" onclick="RequestByPost('hello')" />
</body>
------------webservice.cs----------------------------
[WebMethod]
public XmlNode GetTime(string input)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<envelope><date_time>" + input + " " + DateTime.Now.ToLongDateString() +
DateTime.Now.ToLongTimeString() + "</date_time></envelope>");
return doc.DocumentElement;
}
在IE下可以显示
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetTimeResponse xmlns="http://tempuri.org/"><GetTimeResult><envelope xmlns=""><date_time>hello 2011年6月25日 星期六16:41:27</date_time></envelope></GetTimeResult></GetTimeResponse></soap:Body></soap:Envelope>
-------------------------------------------
在火狐下出现如下提示:
[16:41:38.376] uncaught exception: [Exception... "Component returned failure code: 0x80040154 (NS_ERROR_FACTORY_NOT_REGISTERED) [nsIDOMWindowInternal.alert]" nsresult: "0x80040154 (NS_ERROR_FACTORY_NOT_REGISTERED)" location: "JS frame :: http://localhost/vssnet/test2.aspx :: RequestByPost :: line 166" data: no]
[解决办法]
var URL = "http://localhost/WebService/CityService.asmx/哪个方法";
[解决办法]
JS不行就jquery 如果jquery还是不行就是你代码问题
自己debugger进去跟着 JS调试
或者 自己alert弹出一下
看看进入了 方法没有