Error: Unexpected non-whitespace character after JSON
Can someone help me out how to bind this JSON Data to DropDownList using Xml Request.
{
"statuscode":"200",
"message":"success",
"data":[
{
"StateCode":"AN",
"StateName":"ANDAMAN AND NICOBAR"
},
{
"StateCode":"AP",
"StateName":"ANDHRA PRADESH"
},
{
"StateCode":"AR",
"StateName":"ARUNACHAL PRADESH"
},
{
"StateCode":"AS",
"StateName":"ASSAM"
},
{
"StateCode":"BR",
"StateName":"BIHAR"
},
{
"StateCode":"CA",
"StateName":"CALIFORNIA"
}
],
"count":39
}
function callState() {
if (document.getElementById('drpState').value == '' ) {
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://SearchState.co.in/State.ashx", true);
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200)
{
var data = this.responseText;
var obj = JSON.parse(data);
var objdata = JSON.stringify(obj.data);
objdata = objdata.substr(1);
objdata = objdata.substring(0, objdata.length - 1);
var parsdata = JSON.parse(objdata);
$('#divResult').html(data.StateCode);
///DROP DOWN ///
$('#drpState').value = data.StateCode;
}
else
{
$('#divResult').empty();
var table = '';
table += '<table style="border-collapse: collapse" width="100%" cellpadding="0" bordercolor="#E6E6E6" border="1"><tbody>'
table += '<tr><td style="padding:5px;"><b>Status</b></td><td style="padding:5px;">' + this.responseText + '</td></tr>';
table += '</tbody></table></br>';
}
$('#divResult').html(table);
};
xhttp.send();
}
}