Trying to return data asynchronously using jQuery AND jSon in MVC 2.0
Posted
by Calibre2010
on Stack Overflow
See other posts from Stack Overflow
or by Calibre2010
Published on 2010-06-07T10:17:26Z
Indexed on
2010/06/07
10:22 UTC
Read the original article
Hit count: 350
Hi,
I am trying to use Jquerys getJSON method to return data server side to my browser, what happens is the url the getJSON method points to does get reached but upon the postback the result does not get returned to the browser for some odd reason. I wasen't sure if it was because I was using MVC 2.0 and jQuery 1.4.1 and it differs to the MVC 1.0 version and jQuerys 1.3.2 version. . this is the code sections
Controller
public JsonResult StringReturn() {
NameDTO myName = new NameDTO();
myName.nameID = 1;
myName.name= "James";
myName.nameDescription = "Jmaes";
return Json(myName);
}
View with JQuery
<script type="text/javascript">
$(document).ready(function () {
$("#myButton").click(function () {
$.getJSON("Home/StringReturn/", null, function (data) {
alert(data.name);
$("#show").append($("<div>" + data.name + "</div>"));
});
});
});
</script>
HTML
<input type="button" value="clickMe" id="myButton"/>
<div id="show">d</div>
© Stack Overflow or respective owner