日期:2014-05-17  浏览次数:20455 次

用ajax调用的后台到底哪错了急........
C# code
 <script language="jscript" type="text/javascript">
        var xmlHttp;
        function CreateXmlHttp()
        {
            //创建对象
            if (window.ActiveXObject)
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest)
            {
                xmlHttp = new XMLHttpRequest();
            }
            //加载数据所在的服务器
            var url = window.location.href + "/TestDiv";
            xmlHttp.open("post", url, true);
            xmlHttp.onreadystatechange = Way;
            xmlHttp.send(null);
        }
        function Way()
        {
            if (xmlHttp.readystate == 4 && xmlHttp.status == 200)
            {
                document.getElementById("BindData").innerHTML = xmlHttp.responseText;
            }
        }
    </script>
<div id="BindData">
            </div>
            <input id="Button1" type="button" value="重新绑定" onclick="CreateXmlHttp()"/>


  [WebMethod()]
    public static string TestDiv()
    {
        return "ajax局部刷新!";
    }



------解决方案--------------------
JScript code

 $.ajax({
            type: "post",
            url: "test.aspx/TestDiv",
            data: "{}",
            cache: false,
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function(data) {
               alert(data.d);
            }
        });