Possible Duplicate:
How to parse JSON in JavaScript
Hi I have to parse the following response using AJAX.I have been trying it but I didnt get.
[{"Status":"True"},{"Data":[{"ApplicationNo":"RE09","ApplicationName":"Salim"},{"ApplicationNo":"RE13","ApplicationName":"V Damodaran"}]}]
<script type="text/javascript">
$(document).ready(function () {
$("#btnlogin").click(function (e) {
e.preventDefault();
var txtUsernameID = $("input#useridtxt").val();
var txtPasswordID = $("input#pwdtxt").val();
alert(txtUsernameID+","+txtPasswordID);
$.ajax({
type: 'POST',
//data: '{"username":"' + $("input#txtusername").val() + '","password":"' + $("input#txtpassword").val() + '"}',
url: '',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success:
function (url, textStatus, XMLHttpRequest) {
$.each(url.Data, function(index, item) {
alert(item.agentid);
});
},
error:
function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
});
});
</script>
You don’t need to parse the JSON at all, the
ajaxmethod does that for you when you specify'json'as data type.What you get is an array with two items, and the
Dataproperty is in the object in the second array item, so you reach it usingurl[1].Data: