如何对下面的成功回调函数进行编码,以便能够访问下面返回的 JSON 中的对象。显然,我将无法再访问返回的对象success: function(data) {if (data.returned === true) {
了。我将如何做到这一点?
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:
{
"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"
}
]
}