TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Priyanka P
NA
6
531
Can not read JSON data.
Jul 5 2017 3:37 AM
I am creating application where i send data in form of ajax request and accept in form of JSON, i want to display that JSON data in gridview, but not succeded in it. when i try to print data in JSON(data.d.length) it display 272 (i think it is counting spaces also). I need help in reading data from JSON and bind it to GridView.
In the below way i am sending data to webmethod in ajax request
$.ajax({
type: "POST",
url: "StudentData.aspx/GetData",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
Below code works perfectly fine and send data in JSON format.
[WebMethod]
//public static List<Student> GetData()
public static string GetData(string name)
{
string constr = @"connection string";
string sql = "query";
SqlDataAdapter da = new SqlDataAdapter(sql, constr);
DataSet ds = new DataSet();
da.Fill(ds);
return JsonConvert.SerializeObject(ds, Newtonsoft.Json.Formatting.Indented);
}
//In below code when i print data.d.length it display 272.
function OnSuccess(data) {
alert("In success");
alert(data.d.length);
}
Reply
Answers (
2
)
How To add Custome Js in my Angular2+netcore Webapplication?
How to select distinct case sensitive record using linq inc#