How to retrieve data using json

Posted by Prasanna64 under ASP.NET AJAX on 5/9/2012 | Points: 10 | Views : 2771 | Status : [Member] | Replies : 2
Hi

In controller i had written json code .My json Code is

public JsonResult Get()
{
var data = new {
Id = "1",
Name="prasanna",
Duration="8years",
TrainingYear="2005",
Comments="good comments" };
return Json(data,JsonRequestBehavior.AllowGet);
}

In My view i use

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../../dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue.css" />
<script type="text/javascript" src="../../dhtmlx/dhtmlx.js"></script>
<link rel="STYLESHEET" type="text/css" href="../../dhtmlx/dhtmlx.css" />


</head>

<body onload="doOnLoad()">
<div id="form_container" style="width:250px;height:300px;"></div>
<script type="text/javascript">
var myForm, formData;
function doOnLoad() {
formData = [
{ type: "fieldset", name: "data", label: "Welcome", inputWidth: "auto", list: [
{ type: "input", name: 'id', label: 'Id' },
{ type: "input", name: "Name", label: "Name" },
{ type: "input", name: "Duration", label: "Duration" },
{ type: "input", name: "Training year", label: "Training Year" },
{ type: "input", name: "comments", label: "Comments" },
{ type: "button", name: "submit", value: "submit", id:"submit"}]
}
]
myForm = new dhtmlXForm("form_container", formData);
}
</script>

</body>
</html>
<script type="text/javascript">
var user={

'id':1
};
$('#display').click(function(){
$.get(

'Home/Get',
user,
function(data)
{
alert(data.Name);
}
});
);
</script>


<body>

<form>
<input type="submit" id="display" name="display"/>
</form>
</body>

but am not getting values




Responses

Posted by: Kavi.Sirius on: 5/9/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
Refer this link,

http://www.codeproject.com/Articles/203621/Call-HTTPhandler-from-jQuery-Pass-data-and-retriev


Regards
Kavi.n

Prasanna64, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prasanna64 on: 5/9/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
thanks for the response
I want to include in view page only not as a separate file and in url i has to include 'Home/Get' Home is a controller and get is a method i used like that only but am getting parse error saying could not load my application

Prasanna64, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response