<!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>
<title></title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var Celcius = 0;
$.ajax({
type: "POST",
url: "http:\//www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit",
contentType: "application/x-www-form-urlencoded",
data: 'Celsius=0',
dataType: "text/html",
success: function (msg) {
alert(msg);
},
error: function (xhr, msg) {
alert('fail');
}
});
});
</script>
</head>
<body>
</body>
</html>
将上面的页面保存为.htm文件在桌面上。如果您在浏览器中打开该页面,则会显示“失败”消息。但是,如果你检查小提琴手,那么通话实际上是成功的。在小提琴手中,你也可以看到响应正确地给出了32个答案(web服务转换成0摄氏度到32华氏度)。这在我的桌面上工作了一段时间,然后突然停止工作!为什么成功的消息不工作在这个jQuery的Ajax?
对于那些使用小提琴手的人。这是从提琴手
HTTP/1.1 200 OK
Date: Thu, 05 Apr 2012 23:18:10 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 87
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">32</string>
任何想法?
更新:伙计们,网址http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit是一种网络方法。您无法直接通过浏览器访问它。如果您想通过浏览器发出请求,您可以使用http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit
如果您有使用jquery ajax调用webservice的经验,请仅回复。
如果你只是通常打开网址,你会得到一个错误。也许他们把脚本放下了,或者是因为我试图直接访问脚本? – Armatus 2012-04-05 23:00:57
该网址适用于ajax web服务调用。如果你想访问通过浏览器的网址,它是http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit – developer747 2012-04-05 23:04:11
这是[可能是明智的避免w3schools](http://w3fools.com/ ) – Quentin 2012-04-05 23:06:39