by
slink » Thu Feb 05, 2015 3:02 am
Okay, so now that that's sorted -
I have an AJAX-enabled gallery for crowdsourcing information about historical photos of the local area. Displaying comments already attached to the pictures is part of the goal.
For the database storing the comments (for various reasons, using the comments built into the CMS wasn't going to work), I've got the following code to throw me a JSON file of the comments associated with each picture:
- Code: Select all
<?php require_once ( 'couch/cms.php' ); ?>
<cms:template name="image_id_database" title="Image ID Database" clonable='1'>
<cms:editable type="text" name="photo_number" type="text" required='1' maxlength='3' validator="integer | max_len=3" validator_msg="You must enter a valid picture number." />
<cms:editable type="textarea" name="picture_information" required="1" validator_msg="You must enter information on who is in the photograph, the location, or other points of interest." />
</cms:template>
<cms:set my_photo_id="<cms:gpc method='get' var='id' />"/>
<cms:content_type "application/json" />
[
<cms:pages masterpage='image_id_database.php' custom_field='photo_number=<cms:show my_photo_id />'>
<cms:if k_count=k_total_records >
{"photoComment":"<cms:show picture_information />"}
<cms:else />
{"photoComment":"<cms:show picture_information />"},
</cms:if>
</cms:pages>
]
<?php COUCH::invoke(); ?>
The associated Javascript is:
- Code: Select all
function commentDisplay() {
$('#commentArea').html('');
var requestURL = 'image_id_database.php' + '?id=' + (picNum + 1).toString();
$.getJSON(requestURL,function(data) {
var commentArray = [];
commentArray = data.concat();
if (commentArray.length == 0) {
$('#commentArea').html('<h3 class="alert alert-info text-center">No Comments Available</h3>');
}
else {
for (i=0;i<commentArray.length;i++) {
var newComment = "<div class='list-group-item'>" + commentArray[i].photoComment + "</div>";
$('#commentArea').append(newComment);
}
}
});
};
But the output of the database for a photo with comments associated is:
- Code: Select all
[
]
I've also tried:
- Code: Select all
<cms:pages masterpage='image_id_database.php' custom_field='photo_number=my_photo_id'>
And nothing causes the JSON to output.
I've not a clue what it could be at this point.