This is My jquery function here i append html code inside the function. That's got an error
function onDivisionChange() {
$.ajax({
type : 'POST',
dataType : 'json',
url : '/Example/selectDivision.html',
data : ({
id : $('#division').val()
}),
success : function(responseData) {
if (responseData != null) {
$('#student').find('td').remove().end().append('').val('-1');
$.each(responseData, function(index, item) {
$('#student').append(
$('<td></td>').val(item['id']).html(item['id']),
$('<td></td>').val(item['id']).html(
'<a href="edit.html?id=' + item['id'] + '" >Edit</a>'),
^
|_ Here Error Occured
Error is the '+ item['id'] + ' this line takes as string, not the id value
in browser Link as -> edit.html?id=' + item['id'] + '
Correct format is edit.html?id= 41
$('<br />').val(item['id']).html(item['']));
});
}
}
});
}
If you know about this error please share your answer
EDIT
The page
function onStudentDivisionChange() {
$.ajax({
type : 'POST',
dataType : 'json',
url : '/Example/selectDivision.html',
data : ({
id : $('#division').val()
}),
success : function(responseData) {
if (responseData != null) {
$('#student').find('td').remove().end().append(
'').val('-1');
$.each(responseData, function(index, item) {
$('#student').append(
$('<td></td>').val(item['id']).html(
item['id']),
$('<td></td>').val(item['id']).html(
item['name']),
$('<td></td>').val(item['id']).html(
item['fatherName']),
$('<td></td>').val(item['id']).html(
item['motherName']),
$('<td></td>').val(item['id']).html(
item['admissionNo']),
$('<td></td>').val(item['id']).html(
item['phoneNo']),
$('<td></td>').val(item['id']).html(
'<a href="edit.html?id=' + (item['id']) + '" >Edit</a>'));
alert("Id:"+item['id']);
});
} else {
$('#student').find('td').remove().end().append(
'<td th:text="${student}"></td>').val('-1');
}
}
});
}
console.log(JSON.stringify(item))just before the error line, and report what it outputs.item- an array I guess - of what?item['id']would be undefined. It should be an object.