Reputation: 1007
My AJAX is not working but my JSON result is return row count is 12 and it is not showing any alert messages. I check in browser, it shows 500 internal server error.
If checking purpose I given string value is working for data table is not working there is any other method for getting data table
My JSON Result
public ActionResult GroupFix(string id, string name)
{
List<Tbltable> Fix = new List<Tbltable>();
Fix = entity.Tbltable.Where(x => x.Name == name && x.id == id).ToList();
return Json(Fix, JsonRequestBehavior.AllowGet);
}
My jQuery
$.post("/Home/GroupFix", { name: Name, id : id }, function (result) {
alert('hai');
$.each(result, function (value, key) {
alert('name');
$('#fixtab tbody').append('<tr> <td>' + value.name + '</td> <td>' + value.id + '</td> </tr>');
});
}, "json");
Upvotes: 0
Views: 434
Reputation: 2307
try to Use the ajax post as::
$.ajax({
type:'POST',
Url:"GroupFix",
data:{id=2,name='TestName'},
success:function(data){
for(int i=0;i<data.length;i++){
alert('name');
}
}
})
Upvotes: 1
Reputation: 819
Well not get exact problem, but see below code which work as I wish in my case...
Jquery
$.ajax({
type: "POST",
url: "url",
data: "jason-data",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
var t = window.JSON.parse(msg.d);
// Your code.
}
});
c# code
[WebMethod]
public static string SendMessage()
{
// Code
// return new JavaScriptSerializer().Serialize();
}
Make sure jason key datatype and it's name same as the argument name of method called ba parameters....
Upvotes: 1