使用jQuery调用ASMXWeb服务

使用jQuery调用ASMXWeb服务,jquery,web-services,asmx,Jquery,Web Services,Asmx,我正在尝试使用jQuery调用.NETASMXWeb服务。我一直在使用指南,而且据我所知,我已经完全遵循了它们 服务代码: [WebService(Namespace = "http://tempuri.org/", Description = "...")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] [ScriptService

我正在尝试使用jQuery调用.NETASMXWeb服务。我一直在使用指南,而且据我所知,我已经完全遵循了它们

服务代码:

[WebService(Namespace = "http://tempuri.org/", Description = "...")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class MyService : WebService
{

    private static readonly IKernel NinjectKernel = new StandardKernel(new IocModule());

    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    [WebMethod]
    public string HelloWorld(string name)
    {
        return string.Format("Hello {0}", name);
    }
我可以很高兴地浏览到Firefox中的服务并调用HelloWorld方法

客户端jQuery:

    if (ajaxRunning) {
        return;
    }
    ajaxRunning = true;

    var webMethod = "http://localhost:51546/MyService.asmx/HelloWorld";
    var inputname = "Jack";

    $("[id$='spinner']").show();
    $("[id$='spinnerText']").show();

    $.ajax({
        type: "POST",
        url: webMethod,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: {name: inputname},
        success: function (msg) {
            $("[id$='spinner']").hide();
            $("[id$='spinnerText']").hide();
            ajaxRunning = false;
            alert(msg.d);
        },
        error: function() {
            $("[id$='spinner']").hide();
            $("[id$='spinnerText']").hide();
            ajaxRunning = false;
            alert("Fail");
        }
    });
当我运行javascript时,Firebug中没有错误,只有Fail alert弹出窗口。请告诉我我是否做错了什么事


提前感谢

需要对发送到Web服务的参数进行字符串化。 委员会:

需要替换为:

data: JSON.stringify({name: inputname})
data: JSON.stringify({name: inputname})