我在 C# 中有一个 WebService,我想从另一个应用程序访问这个 WebService。前任。有一个在 localhost 中运行的 web 服务,我也有一个在 localhost 中运行的网站,这两个项目位于不同的地方。问题是:如何在本地主机中使用 ajax 从我的网站调用此 Web 服务。
我拥有的代码是这样的:WebService
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public String HelloWorld()
{
return "Hello World";
}
}
和客户
$.ajax({
type: "POST",
url: "localhost:52137/Service1.asmx?op=HelloWorld",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: '',
success: function (data, status) {
alert(data.d);
},
error: function(data, status){
alert(status);
}
});