调用C#的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");
}
}
}
定义一个WebMethod,我必须做出一个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控制台中的问题我得到了这个!
的你有没有尝试把;在警报声明的末尾。此外,请提及错误,因为在图像中不容易阅读。还有一个建议,在你的ajax调用中使用单引号而不是double。 – rach
这就是问题在于错误是不可读的;没有改变任何东西! –