아래에서 반환 된 JSON의 객체에 액세스하려면 어떻게해야 성공 콜백 함수를 코딩해야합니까? 분명히 더 이상 success: function(data) {if (data.returned === true) {
을 사용하여 반환 된 객체에 액세스 할 수 없습니다. 나는 어떻게 이것을 성취 할 것인가?다중 반환 데이터 구조에서 JSON 객체에 액세스
jQuery를 코드 :
$("#projects").click(function() {
jQuery.ajax({ type: "POST", dataType: "JSON",
url: "<?=base_url()?>index.php/home/projectsSlider",
json: {returned: true}, success: function(data) {
if (data.returned === true) {
$("#resultProjects").html(JSON.stringify(data.Projects));
$("#resultScreenshots").html(JSON.stringify(data.Screenshots));
$("#content").fadeOut(150, function() {
$(this).replaceWith(projectsSlider(data.projectId, data.projectName, data.startDate, data.finishedDate, data.projectDesc, data.createdFor, data.contributors, data.screenshotURI, data.websiteURL), function() {
$(this).fadeIn(150);
});
});
}
}
});
});
반환 된 JSON : 내가 제대로 문제를 이해하지만, 당신이 JSON을 호출 할 때 원래 JSON 영구적으로 수정 얻을 수 있다는 우려 보인다 확실하지
{
"Projects": [
{
"projectId": "932713684f9073189ec7b",
"projectName": "Cloud859Collective",
"startDate": "April 19th, 2012",
"finishedDate": "April 25th, 2012",
"createdFor": "ClasskCreations",
"contributors": "Mike Grigsby",
"projectDesc": "This website was created with a friend in mind. His name is Kevin Johnson and he is a rapper. He needed a website that would allow him to host and share his music."
},
{
"projectId": "10599012654f907093714e9",
"projectName": "Nurbell Studio",
"startDate": "April 15th, 2012",
"finishedDate": "April 19th, 2012",
"createdFor": "Nurbell LLC",
"contributors": "Mike Grigsby",
"projectDesc": "This is the page you are currently looking at. This is the official Nurbell homepage. Complete with a frontend and a backend."
}
],
"Screenshots": [
{
"screenshotURI": "http://nurbell.com/vd/1.0/images/project-data/kevo.png"
},
{
"screenshotURI": "http://nurbell.com/vd/1.0/images/project-data/nurbell.png"
}
]
}
http://pastebin.com/j6XncXmd - 이와 비슷한 기능이 있습니까? '잡히지 않는 구문 오류 : 예기치 않은 토큰}'오류가 발생합니다. 또한'projectsSlider()'에서'data.projectId'에 어떻게 접근해야합니까? –
잘, 각 함수는 첫 번째 인수 (myProjects.projects)의 배열에있는 모든 요소를 반복 한 다음 두 개의 매개 변수가있는 명명되지 않은 함수에 해당 요소를 전달합니다. i = 배열 요소의 인덱스 (예 : myProjects.projects [i]와 같은 것을 변경하고 두 번째 요소는 요소의 내용입니다. 그래서 당신은 e.projectId ....에 의해 projectId를 참조 할 수 있습니다. (함수 인수에서 e를 데이터의 이름으로 바꿀 수도 있지만, 그렇게되면 혼란 스러울 것입니다. http://pastebin.com/PiDBBB0S – Jeroen
은 다른 오타를 발견했습니다. 또한 가독성을 위해 들여 쓰기가 변경되었습니다 : http://pastebin.com/AcDBKtCR – Jeroen