i am having a strange problem, while calling ajax jquery in asp.net.. i am getting the parseError, and this is not expected, because everything is in place.
below is my webmethod.
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; }
}
}
below is the method i am calling
[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 dtTopStorie开发者_Go百科s.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();
}
and below is the design.
<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>
Please any know what could be issue i am using core asp.net and master pages in my application.
******************JSON RESPONSE*****************
<!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>
Try replacing:
data: {},
by:
data: '{}',
精彩评论