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.

executable
  • 3,365
  • 6
  • 24
  • 52
  • 1
    display in console.log – Jax Teller Nov 15 '18 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` – Nikos M. Nov 15 '18 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))` – Karim Nov 15 '18 at 13:55
  • Try to console your response. console.log(response), then see what you are getting there – Sajjad Ali Nov 15 '18 at 13:55
  • hey... Try to `console.log()` your response? xD – Stender Nov 15 '18 at 14:07

1 Answers1

4

Let's try with

JSON.stringify it will convert the object response to string

alert(JSON.stringify(response));

taile
  • 2,738
  • 17
  • 29
  • Thanks Tai Le, already tried with this solution, but not able to store that result in Table. – Mohammad Sarfaraz Nov 15 '18 at 13:54
  • hmm. which table? – taile Nov 15 '18 at 13:57
  • I have used in view
    so, i want to store json response in this table. Tai Le can you please help.
    – Mohammad Sarfaraz Nov 15 '18 at 14:00
  • I found some answers here: https://stackoverflow.com/questions/17724017/using-jquery-to-build-table-rows-from-ajax-response-json – taile Nov 15 '18 at 14:03
  • @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](https://meta.stackoverflow.com/a/258279/5947043). Instead, if you have a new problem and can't solve it by your own research and coding, then ask a new question. – ADyson Nov 15 '18 at 14:06