0

I am fetching one row from database in Object format.

here is my .cs code

public JsonResult GetApplicationDetail(string id){
    sp_Application_Result AppObj = new sp_Application_Result();
    ObjectResult obj = db.sp_Application(id);
    foreach (sp_Application_Result i in obj){
        AppObj = i;
    }
    return Json(AppObj, JsonRequestBehavior.AllowGet);
}

and here is my script code

$.ajax({
    type: "GET",
    url: "/Application/GetApplicationDetail/",
    datatype: "json",
    data:  {"id" : name} ,
    success: function (response) {
        alert(response);
    }
);  

when I'm trying to show response, it's showing [Object,object]

I am not getting how to show response result, actually I want to store response data into table.

5
  • 1
    display in console.log Commented Nov 15, 2018 at 13:53
  • only console.log(response) can expand and print objects, instead alert can only print/display strings so either use console.log or JSON.stringify(response) before alert Commented Nov 15, 2018 at 13:53
  • Either you can log the response directly using console.log(response) or you can transform the json object to string to be able to display it in the alert alert(JSON.stringify(response)) Commented Nov 15, 2018 at 13:55
  • Try to console your response. console.log(response), then see what you are getting there Commented Nov 15, 2018 at 13:55
  • hey... Try to console.log() your response? xD Commented Nov 15, 2018 at 14:07

1 Answer 1

4

Let's try with

JSON.stringify it will convert the object response to string

alert(JSON.stringify(response));

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

5 Comments

Thanks Tai Le, already tried with this solution, but not able to store that result in Table.
hmm. which table?
I have used in view <table id="datatable"> </table> so, i want to store json response in this table. Tai Le can you please help.
I found some answers here: stackoverflow.com/questions/17724017/…
@mohdsarfaraz that's really a totally separate issue to the problem you illustrated in the question. It's unrelated and is a different task you need to complete. Don't be a help vampire. Instead, if you have a new problem and can't solve it by your own research and coding, then ask a new question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.