<script type="text/javascript" src="jquery-1.7.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Text1").blur(function () {
            var text = this.value;
            var options = {
                type: "post",
                url: "基于netAjax.aspx/Getavail",
                data: "{no:" + text + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    alert(response);
                    alet("11111");
                    
                }
            };
            $.ajax(options);
        }
        );
    }
    );
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <input id="Text1" type="text" /></div>
C#:
public partial class Ajaxxxxnet_基于netAjax : System.Web.UI.Page
{
    [WebMethod]
    protected void Page_Load(object sender, EventArgs e)
    {    }
    
    public static string Getavail(int no)
    {
        string noo = Convert.ToString(no);
        string result = "成功" + noo;
        return result;
    }
public partial class Ajaxxxxnet_基于netAjax : System.Web.UI.Page
{
    [WebMethod]
    protected void Page_Load(object sender, EventArgs e)
    {    }
    
    public static string Getavail(int no)
    {
        string noo = Convert.ToString(no);
        string result = "成功" + noo;
        return result;
    }
////这是我试验的一个小例子,小弟初学ajax,求指教,为什么成功呢?

解决方案 »

  1.   

    $(function () {
                $("#text1").blur(function () {
                    var text = $(this).val();
                    $.ajax({
                        type: "post",
                        url: "基于netAjax.aspx/Getavail",
                        data: "{no:" + text + "}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            alert(response);
                            alet("11111");
                        }
                    });
                });
            });
      

  2.   

    如果只是alert出成功,那说明你没成功。
    如果成功后面还有,那说明你才成功了。
      

  3.   


    $(function () {
                $("#text1").blur(function () {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json",
                        url: "../WebService1.asmx/HelloWorld",
                        data: "{msg:'alpha'}",
                        dataType: 'json',
                        success: function (result) {
                            alert(result.d);
                        },
                        error: function (e) { alert('error'); }
                    });
                });
            });
      

  4.   


    到w3school看下 非常好