Проблема с вызовом jquery ajax в asp.net - PullRequest
0 голосов
/ 23 сентября 2011

У меня странная проблема, когда я вызываю ajax jquery в asp.net .. Я получаю 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>

1 Ответ

1 голос
/ 23 сентября 2011

Попробуйте заменить:

data: {},

по:

data: '{}',
...