Skip to content

Instantly share code, notes, and snippets.

@ramons03
Last active December 19, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramons03/5997796 to your computer and use it in GitHub Desktop.
Save ramons03/5997796 to your computer and use it in GitHub Desktop.
Parse a json result from asp MVC controller and set a variable in javascript with an attribute from the json object.
function getData(url) {
var data;
$.ajax({
async: false, //thats the trick
url: url,
dataType: 'json',
success: function (response) {
data = response;
}
});
return data.JsonAttribute;
}
var jsVar = getData('@Url.Action("getJson", "Controller")');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment