I got JSON String object from backend.My Json String object contains id and en_name.Now i want to populate only en_name on my dropdown.
I ma getting this error:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data..
This is my JSON String Object.
[{"id":2773,"environments_name":"ABC-DEF"},{"id":2770,"environments_name":"ABCS- - DSDSDSFR"
},{"id":2774,"environments_name":"GFDSS - GGGDFF"}] .
//this my ajax call
<script>
$(document).ready(function() {
$("#customerDetails").change(function() {
var value1 = $('#customerDetails :selected').text();
$.ajax({
type : 'GET',
url : 'environments',
data : {
selectedcustomername : value1
},
success : function(result) {
getEnvNames(result);
}
});
});
});
</script>
//this is my function
<script language="JavaScript">
function getEnvNames(result){
alert("inside the function");
var item= result;
alert("rowwwww>>>>"+row);
var select="<select id='environmentName'>";
for(var i=0,i=row.length;i>1;i++){
var item=JSON.parse(row[i]);
alert("for loop");
var item=row[i];
//Here I am getting item value is undefined.
alert("itemmmmmmmm>>>"+item);
alert("row[i],,,,,,>>>"+row[i]);
select+="<option value='"+item.id+"'>"+item.name+"</option>";
}
select+="</select>";
document.write(select);
}
</script>
This is my JSP
<td aligh="right">Select Environemnt : <select
name="environmentName" id="environmentName">
<option selected="selected" disabled="disabled">Select An Environment</option>
</select></td></tr>