Asp.net 你能帮我找出为什么我对HelloWorld webservice的$.ajax调用在这里失败吗?

Asp.net 你能帮我找出为什么我对HelloWorld webservice的$.ajax调用在这里失败吗?,asp.net,web-services,jquery,Asp.net,Web Services,Jquery,我正在尽我最大的努力,但我不明白为什么我没有得到这样一个简单的web服务的成功响应;你能看一下吗?请告诉我我错过了什么 每次只调用error函数,Fiddler说我有HTTP响应500 谢谢 附加说明: 我检查了Fiddler,上面写着: 在:/JQuery Recepie/Chapter16 Ajax/MyWebService.asmx中找不到web服务。但为什么 我的Web服务类: [WebService(Namespace = "http://tempuri.org/")] [WebSer

我正在尽我最大的努力,但我不明白为什么我没有得到这样一个简单的web服务的成功响应;你能看一下吗?请告诉我我错过了什么

每次只调用error函数,Fiddler说我有HTTP响应500

谢谢

附加说明: 我检查了Fiddler,上面写着: 在:/JQuery Recepie/Chapter16 Ajax/MyWebService.asmx中找不到web服务。但为什么

我的Web服务类:

[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 MyWebService : System.Web.Services.WebService {

    public MyWebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

}
绑定到按钮单击事件(调用Web服务)的我的JavaScript:

function jqHelloCall(){

        $.ajax({ type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "MyWebService.asmx/HelloWorld",
        data: "{}",
        dataType: "json",
        success: function(msg){
                            alert(msg==null);
                            alert(msg.d);
                                    },
        error:      function(){
                            alert('error'); 
                                }

             }); }

使用Firefox中的Firebug查看IIS发送的响应。在网络选项卡上的Firebug中,您只能过滤Ajax请求(XHR)。您肯定会在IIS将发送回的响应正文中找到有关服务器异常的所有详细信息

铅笔蛋糕:我检查了Fiddler,它说:在:/JQuery Recepie/Chapter16 Ajax/MyWebService.asmx上找不到web服务。但为什么

因为web方法应该是静态的

[WebMethod]
public static string HelloWorld() {
    return "Hello World";
}

将scriptMethod属性添加到服务方法

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld() {
        return "Hello World";
    }

你确定URL是正确的吗?通常它们以
/
开头。通过直接在浏览器栏中键入URL或使用curl来检查您的URL。@ZeissS,如果URL不正确,他会从服务器上得到404错误,而不是500。@pencilCake,这个
jqHelloCall
函数是如何调用的/where/在什么上下文中调用的?还有关于500错误的详细信息吗?什么是异常文本?@DarinDimitrov:我检查了Fiddler,它说:在:/JQuery-Recepie/Chapter16 Ajax/MyWebService.asmx上找不到web服务。但为什么@János Nagy如果有HTTP响应500,请求肯定会到达服务器。我不这么认为。我能够从asp.net MS Ajax调用中调用相同的实例方法,而不会出现问题。但jQuery并没有做到这一点。(我也尝试过你的方法,但没有任何改变)谢谢。@pencilCake我完全没有注意到该方法是WebService WebMethod而不是ASPX page WebMethod,对不起。当你使用MS Ajax调用该方法和使用jQuery调用该方法时,你是否比较了请求头?