에 오류를 받고 있어요 내가 콘솔나는이 샘플 JSON 코드가 구문 분석 JSON
에 오류가이 파일 NEW_CONTENT의 코드 항상이 jQuery를 AJAX로하지만 어떤 이유로 루프를 통해 원하는. JSON
[
{
"name": "Mehmet",
"email": "[email protected]"
},
{
"name": "Fareed",
"email": "[email protected]"
},
{
"name": "Jonathan",
"email": "[email protected]"
}
]
이는 내 HTML은
<div id="main">This is the original text when page loads</div>
<button id="button1" type="button">Update content with Ajax</button>
이는 자바 스크립트 내부
$(document).ready(function(){
$("#button1").on('click', function() {
$.ajax({
type: "GET",
url:"new_content.json",
success:function(rawData){
var data = JSON.parse(rawData);
var result = '';
result += '<table> \
<tr> \
<th>name</th> \
<th>email</th> \
</tr> \
<tr>';
$.each(data, function(i, item) {
result += "<tr><td>" + item[i].name + "</td>";
result += "<td>" + item[i].email + "</td></tr>";
}
result += "</tr></table>";
$("#main").html(result);
}
});
});
});
콘솔에서 오류가 무엇인가에 확인 모든 것이 잘 될 것입니다? –
rawData는 이미 JSON이므로 구문 분석 할 필요가 없습니다. 먼저 console.log를 시도하십시오. –
ajax 메소드 응답이 application/json 유형이면 구문 분석 할 필요가 없습니다. – nerdcoder