网络服务看起来像
using System;<br/>
using System.Collections.Generic;<br/>
using System.Linq;<br/>
using System.Web;<br/>
using System.Web.Services;<br/>
[WebService(Namespace = "http://tempuri.org/")]<br/>
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br/>
[System.Web.Script.Services.ScriptService] <br/>
public class Map : System.Web.Services.WebService
{
[WebMethod]
public MapClass LatitudeLongitude()
{
MapClass mapobj = new MapClass();
return mapobj;
}
[WebMethod]
public string helloToYou()
{
return "Hello";
}
}
类看起来像:
public class MapClass <br/>
{
string latitude;
string longitude;
public MapClass()
{
latitude = "51.508742";
longitude = "-0.120850";
}
}
我正在尝试从 html5 页面调用网络服务
`</head>`<br/>
`<body>`<br/>
`<form id="form1" runat="server">`<br/>
`<h1>Map</h1>`<br/>
`<input id="View" type="button" value="Click to view" onclick="getData()"/>`<br/>
`</form>`<br/>
`</body>`<br/>
`<script type="text/javascript" src="D:\PepsiCO\jQuery\jquery-1.7.1.min.js"> </script>`<br/>
`<script type="text/javascript">`
function getData() {
$.ajax({
type:"POST",
url: "http://localhost:53788/HTML5_WebService_Maps/Map.asmx/helloToYou",
contentType: "application/json;charset=utf-8",
dataType: "json",
complete: function (response)
{ alert('complete'); },
success: function (response)
{ alert('Success'); },
error: function (response)
{ alert('Failure'); }
});
}
`</script>`
`</html>`
当我在 chrome 中浏览 html 页面时,它在警告框中显示失败。不知道为什么它没有显示成功。请帮忙。