I created a text called Name under my content folder. I wrote it in Json format. I am trying to take that Name.text and display it after the result of clicking a button. I came up with some parsing code to parse the json. I just dont know where to put it at. I think it go in my success: function(data) area somewhere. Please help me out.
<p>
<script type ="text/jscript">
$(document).ready(function () {
$.ajax({
url: "/MvcApplication1/Content/Name.txt",
success: function (data) {
var jsnObj=$parseJSON(data);
$("#button").click(function(){
$("p").append(jsonObj.First);
$("P".append(jsonObj.Last);
});
},
error: function () {
alert("error");
}
});
});
</script>
</p>
<div id="nameDiv"></div>
<button id ="button><Get Name</button>
yes, create 2 functions, one that does the Ajax and one that does the parsing, you need to pass the “data” to the parse function .
NB* you can simplfy further – see getJSON for examples –http://api.jquery.com/jQuery.getJSON/