0

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");
4
  • Can you show your JSON-formatted response instead of the code that created it? Commented Mar 14, 2014 at 7:08
  • Well, something's happening inside your server. It might as well be a data base server problem. Just try to debug it. First, make it return a static text and see if the browser connects to the action or not... Commented Mar 14, 2014 at 7:23
  • if i pass the string value is will be return but data table is not responding Commented Mar 14, 2014 at 7:33
  • See that post i m not getting answer Commented Mar 15, 2014 at 5:23

2 Answers 2

1

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....

Sign up to request clarification or add additional context in comments.

5 Comments

its returning single value but i need to pass data table
You can pass datatable .. return new JavaScriptSerializer().Serialize(new Hashtable { { "r", "Message sent successfully." } }); as the same I am doing ...
return new JavaScriptSerializer().Serialize(new Hashtable { { Fixture } }); its right its showing error no overload for method 'Add' take 1 argument
Try this. return new JavaScriptSerializer().Serialize(Fixture ); I guess it helps u...
Cannot implict convert type 'string' to 'System.web.mvc.Actionresult' error is coming to this code return new JavaScriptSerializer().Serialize(Fixture );
1

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');
        }
    }
})

3 Comments

Ya friend my ajax is working for display string one getting single row from the database but it not getting more than one row from the data base
then have a look in your controller's action code by using breakpoint that how many results you get from database.
Ya friend it can return 12 row count as a list but in my view is not showing any alert message also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.