jQuery:对asp.net Web服务的Ajax调用失败,服务器返回500错误

好的,所以我创建了一个测试项目,只是为了验证jQuery AJAX是否可以与asp.net服务一起使用,并且没有问题.我使用了在VS studio中创建的默认HelloWorld服务.我通过jQuery这样调用服务:

在Default.aspx中:

<script language="javascript" type="text/javascript">
    $(document).ready(function() {

        //test web service
        $.ajax({
            type: "POST",contentType: "application/json; charset=utf-8",url: "TestService.asmx/HelloWorld",data: "{}",dataType: "json",success: function(msg) { alert(msg);},error: function (XMLHttpRequest,textStatus,errorThrown) {
                debugger;
            }
        });
    });
</script>

在TestService.asmx中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebServiceTestWitJQuery
{
    /// <summary>
    /// Summary description for TestService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 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 TestService : System.Web.Services.WebService
    {

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

然后,我继续进行操作,并完全复制了项目中的所有内容,但它不起作用.我收到500个服务器错误.

我验证了以下内容:

> web.configs相同
>页面相同
>服务等级相同
> jQuery Ajax调用相同
>我可以导航到http://localhost:3272/TestService.asmx?op=HelloWorld,并且Web服务可以正常工作.

还有什么?

最佳答案
弄清楚了.如果不确定发生了什么,请使用Fiddler.它清楚地表明服务器无法创建服务类的实例,因为它在错误的名称空间中.我禁用了R#,并且没有注意到我没有更改服务的名称空间.问题解决了.

相关文章

1.第一步 设置响应头 header(&#39;Access-Control-Allow...
$.inArray()方法介绍 $.inArray()函数用于在数组中搜索指定的...
jquery.serializejson.min.js的妙用 关于这个jquery.seriali...
JS 将form表单数据快速转化为object对象(json对象) jaymou...
jQuery插件之jquery.spinner数字智能增减插件 参考地址:http...