Ajax与asp.net aspx返回未定义

我面临以下问题:每当我点击buttonalert显示undefined

Web方法:

    [WebMethod]
    public static string getTest()
    {
        return "testing success";
    }

Ajax脚本

    <script type="text/javascript">
        function getTest() {
            $.ajax({
                type: "POST",
                url: "main.aspx/getTest",
                data: "{}",
                datatype: "json",
                contenttype: "/application/json; charset=utf-8",
                success: function (msg) {

                    alert(msg.d);

                },
                error: function (data) {
                }
            });
        }
    </script>

datatype应该是dataTypecontenttype应该是contentType 。 还要从"/application/json; charset=utf-8"开始删除/

$.ajax({
            type: "POST",
            url: "main.aspx/getTest",
            data: "{}",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: function (msg) {

                alert(msg.d);

            },
            error: function (data) {
            }
        });

从你的ajax调用中移除这些

datatype: "json",
contenttype: "/application/json; charset=utf-8",

更多关于这些

jQuery ajax函数中contentType和dataType之间的区别

AJAX请求中的内容类型和数据类型是什么?

你可以在jQuery Ajax文档中找到更多细节

链接地址: http://www.djcxy.com/p/46147.html

上一篇: Ajax with asp.net aspx returns Undefined

下一篇: Requested JSON parse failed in jquery ajax