I need to populate some data into a table. The data I have is something I get in response from my ASP.NET MVC site, when I make a JSON post call there. Yet I can't seem to find a way to actually display the data I get back in response. Here is my code so far. Any help would be much appreciated:
$(document).ready(function () {
var uName = '<%= Session["UserName"].ToString()%>';
var pWord = '<%= Session["Password"].ToString()%>';
var data = { UserName:uName,Password:pWord};
$.ajax( {
type: 'POST',
url: "http://someurl.goes.here/",
crossDomain: true,
data: data,
dataType: 'jsonp',
success: function(myData) {
$.each(myData, function (index, element) {
$("#ClassTable").append('<tr><td> ' + element[0] + ' </td> <td> ' + element[1] + '</td></tr>');
})
}
});
});
myData looks like this:
[Object { IsActive = True, ObjectId=1, ObjectString="someString", etc... etc... } ]
It's not a good idea to store the user's password in plain text on the page. Even if you're using HTTPS. If you're using HTTP, then it's very easy to see the password. You should not even be storing a password in plain text.
I think this is your error:
element is { IsActive = True, ObjectId=1, ObjectString="someString", etc... etc... } which is not what you probably think it is. It has no key 0 or 1, so if your syntax is correct, every element will be "undefined".
You need to use Chrome's developer tools to debug your code. Pause it in the success callback and evaluate properly what data you're getting and what's getting written to the DOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With