this is a complete noob question, but I am brand new to javascript and web development, so please bear with me :)
I have objects in a Parse class that I want to list on a website. I want to iterate through these objects and list them (I am in an html file).
Here is my code:
<script>
Parse.initialize("XXXXXXX");
var Post = Parse.Object.extend("Post");
function getPosts() {
var query = new Parse.Query(Post);
query.find({
success: function(results){
var output = "";
for (var i in results) {
var title = results[i].get("activityTitle");
console.log("ok now");
output += "<div class=\"row container-post\">
<div class=\"col-md-4 col-sm-6\">
<div class=\"post-container\">
<div class=\"post-content no-padding\">
<img src=\"assets/image-portfolio-02.jpg\" alt=\"danish personal blog template\"></div>
<div class=\"post-content\">";
output += title;
output += "</div></div></div></div>";
}
$("#list-posts").html(output);
}, error: function(error) {
console.log("Query Error:"+error.message);
}
});
}
getPosts();
</script>
alert(...), useconsole.log(...)instead. Alert is process blocking, which you generally don't want. Use the dev tools, and look at the console: allconsole.log(...)calls will write data there. And not just strings, unlikealerttheconsole.logfunction can take any input and properly show it. As secondary tip: modern HTML does not require you to saytype="text/javascript"for a script element. That's 1998's HTML4.01, which we're no longer using =)