JS如下
            $.ajax({
                type: "POST",
                contentType: "application/xml; charset=utf-8",
                url: "Services/GetNotice.asmx/GetNoticeList",      
                data: '{"CPUID":"BFEBFBFF00010677"}',  
                dataType: 'xml',
                error:function(XMLHttpRequest, textStatus)
                {
                  alert("天杀的出错了");  
                },
                success: function(result) {               
                    var cc = "";
                    $(result).find("Message").each(function() {
                        cc += "<a href='messageView.aspx?mesid="
                        cc += $(this).find("MessageID").text();
                        cc += "' target='_blank' style='margin-right:15px";
                        if ($(this).find("IsImportant") == 'true')
                        { cc.html += ";color:Red"; }
                        cc += "'>";
                        cc += $(this).find("MessageTitle").text();
                        cc += "</a>"
                    });
                    $("#rollingNotice").html(cc); alert(cc);
                    $("#rollingNotice").marquee('pointer').mouseover(function() {
                        $(this).trigger('stop');
                    }).mouseout(function() {
                        $(this).trigger('start');
                    });
                }
            });
webservice如下
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]    
    public List<Message> GetNoticeList(string CPUID)
    {
        MessagesDataContext msd = new MessagesDataContext();
        var query = from p in msd.Message
                    where p.ToPerson.Trim().ToLower() == CPUID.ToLower() || p.ToPerson.Trim().ToLower() == "all"
                    select p;
        return query.ToList();    }
这样看似没问题,但是根本访问不到这个webmethod,直接蹦出个error,如果把参数去掉就可以访问到了
应该还是js部分有错误,那位高手帮忙瞧瞧,没怎么接触过jQuery

解决方案 »

  1.   

    你直接用vs调试你的js代码 看看都是什么值啊 ??
      

  2.   

    你的webservice有没有加了
    [System.Web.Script.Services.ScriptService]
    还有这个web.config中药添加这个:
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    还有就是更多的信息,你可以去cnblogs上找jquery ajax肯定有很多的资料
      

  3.   

    //若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
    //[System.Web.Script.Services.ScriptService] 
    从这看,它和我出现的问题并没有什么关系吧
    试了试,加不加都是出错js调试代码
    直接就蹦到error了,不知道怎么调试,有什么招数么
      

  4.   


    contentType: "application/xml; charset=utf-8", 
    dataType: 'xml', contentType: "application/json; charset=utf-8", 
    dataType: 'json', 
      

  5.   

    webservice那头定义的就是ResponseFormat.Xml,就算是我改成Json
    把datatype改成json也是不行
    调试了一下看压根就没往webservice的方法去,直接就蹦到error了
    不明白啊
      

  6.   

     type: "POST",
                    url: "Services/GetNotice.asmx/GetNoticeList",
                    data: '{"CPUID":"BFEBFBFF00010676"}',
                    dataType: 'xml',
                    contentType: "application/json; charset=utf-8",
                    error: function(XMLHttpRequest, textStatus) {
                        alert("天杀的出错了");
                    },这么写就对了
      

  7.   

    如果把datatype也改成json的话,数据去不出来,不知道为什么,不管了
    结贴