我想问一下,.net2005是不是不能使用jQuery调用webService?
在查询资料中,有帖子说需要加入引用
1)System.Web.Extensions;
2)using System.Web.Script.Services;
但始终没有加入,最后又看见说添加
1)Microsoft.Web.Extensions.Design.dll
2)Microsoft.Web.Extensions.dll
这两个dll,
但添加了之后,也配置了Config,但还是不能引用希望各位大侠帮帮小弟,给点建议!!!
非常感谢,献上30分做为谢礼(前不久赚来的,我的分啊~~~)

解决方案 »

  1.   

    可以的,不过不能调用页面级的pageMethod.webmethod 是没问题的
      

  2.   


    function DiggIt(entryId, diggType, blogId) {
            
        $.ajax({
            url: 'Public/MyService.asmx/HelloWorld',
            data: '{}',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json; charset=utf8',
            success: function(data) {
                $("DigTip_"+blogId).append(data.d)
            },
            error: function(xhr) {
                alert("提交出错,请重试。错误信息:" + xhr.responseText);
            }
        });
    }
    提示:           提交出错,请重试。错误信息:using System;
    using System.Web;
    using System.Collections;
    using System.Web.Services;
    using System.Web.Services.Protocols;/// <summary>
    /// MyService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class MyService : System.Web.Services.WebService {    public MyService() {
            
            //如果使用设计的组件,请取消注释以下行 
            //InitializeComponent(); 
        }    [WebMethod]
        public string HelloWorld() {
            return "Hello World";
        }}
      

  3.   

    $.ajax({
    url:"Digg.aspx?action="+ftype+"&id="+aid+" &time="+new Date().toString(),
    type:'GET',
    success:function(){
    $('#newdigg').html(arguments[0]);
    }
    });
    }
      

  4.   

    $.ajax({
                        type: "POST",
                        url: "Public/MyService.asmx/HelloWorld",
                        data: "",
                        contentType: "application/x-www-form-urlencoded; charset=utf-8",
                        dataType: "json",
                        success: function(data) { $("DigTip_"+blogId).append(data.d)
            },
            error: function(xhr) {
                alert("提交出错,请重试。错误信息:" + xhr.responseText);
            }
                    });
      

  5.   

    [WebMethod]
        public void HelloWorld() {
            Response.Write("Hello World");
        }
    ajax 其实就是请求 
      

  6.   

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]  //令WebService成功传入Json参数,并以Json形式返回结果
    [GenerateScriptType(typeof(Person))]  //不是必要,但推荐添加(如果Person里面再嵌套另一个复杂类型,则必要声明)
    [ToolboxItem(false)]
      

  7.   

    问题终于解决
    不应该是
     dataType: "json", 
    而应该是
     dataType: "html", 
    可能是因为jQuery的代码
      

  8.   

    这个你试了么$.ajax({ 
                        type: "POST", 
                        url: "Public/MyService.asmx/HelloWorld", 
                        data: "", 
                        contentType: "application/x-www-form-urlencoded; charset=utf-8", 
                        dataType: "json", 
                        success: function(data) { $("DigTip_"+blogId).append(data.d) 
            }, 
            error: function(xhr) { 
                alert("提交出错,请重试。错误信息:" + xhr.responseText); 
            } 
                    });
      

  9.   

    需要将dataType: "json",修改为dataType: "html",
    而且Webservice中的必须用Context.Response.Write("")进行输出,不能用Return.
    而取值 的时候直接给data,不是data.d
      

  10.   

    data.d是 我返回的json 的格式,可能这个有区别
    但 你用 dataType: "json" 获得不到 数据 应该是 你返回的不是json 格式的数据所以 dataType: "html", 然后用  Context.Response.Write("") 输出