我需要调用这个类中定义的 webmethod
<%@ WebService Language="C#" Class="emt7anReyady.myService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Linq;
using System.Web.Security;
namespace emt7anReyady
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class myService : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public void test()
{
Context.Response.Redirect("http://www.google.com");
}
}
}
我打了一个像这样的 Ajax 调用
function getData() {
$.ajax({
type: "POST",
url: "myService.asmx/test",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert("succesed")
},
failure: function () {
alert("faild")
}
});
}
呼叫失败的问题,在 chrome 控制台中我得到了这个!