0

我在 asp.net 中调用 ajax jquery 时遇到了一个奇怪的问题。我得到了 parseError,这是意料之外的,因为一切都准备好了。

下面是我的网络方法。

public class MyLogic
{
    private int _id;

    public int Id
    {
        get { return _id; }
        set { _id = value; }
    }
    private string _title, _image;

    public string Image
    {
        get { return _image; }
        set { _image = value; }
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }
}

下面是我正在调用的方法

[WebMethod]
    public static MyLogic[] GetTopArticles()
    {
        List<MyLogic> bList = new List<MyLogic>();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MobileKeyboardConnection"].ConnectionString);
        SqlDataAdapter adapTopStories = new SqlDataAdapter("m_sp_toparticles", con);
        adapTopStories.SelectCommand.CommandType = CommandType.StoredProcedure;
        adapTopStories.SelectCommand.Parameters.AddWithValue("@PortalId", 2);
        adapTopStories.SelectCommand.Parameters.AddWithValue("@topValue", 5);
        DataTable dtTopStories = new DataTable();
        adapTopStories.Fill(dtTopStories);
        foreach (DataRow r in dtTopStories.Rows)
        {
            MyLogic c = new MyLogic();
            c.Id = Convert.ToInt32(r["Id"]);
            c.Title = r["Title"].ToString();
            c.Image = r["image"].ToString();
            bList.Add(c);
        }
        return bList.ToArray();
    }

下面是设计。

<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            url: "AjaxLogic.aspx/GetTopArticles",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: "{}",
            success: function (data) {
                var result = data.d;
                alert(result.length);
            },
            error: function (data) {
                alert(data.responseText);
            }
        });
    });
</script>

请知道我在我的应用程序中使用核心 asp.net 和母版页可能会出现什么问题。

** * ** * ** * ** * ** * ** * JSON 响应* ** * ** * ** * ** * ****

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title></head>
<body>
    <form name="form1" method="post" action="AjaxLogic.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZPKFQelTZBrnZbMRGP+4imyXfwO4" />
</div>

    <div>

    </div>
    </form>
</body>
</html>
4

1 回答 1

1

尝试更换:

data: {},

经过:

data: '{}',
于 2011-09-22T20:11:01.440 回答