Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 13 2018 17:18
    lightyaer opened #87
  • Nov 01 2018 17:27
    mattbyrnes opened #86
  • Nov 01 2018 16:36
    mattbyrnes opened #85
  • May 24 2018 18:05
    jromest opened #84
  • Mar 24 2018 23:01
    MiloATH closed #77
  • Mar 24 2018 23:00
    MiloATH closed #17
  • Mar 12 2018 19:17
    paperplanes53 closed #81
  • Nov 26 2017 12:41
    CharanyaR opened #83
  • Nov 03 2017 11:24
    Prescise opened #82
  • Sep 27 2017 18:44
    cd-Zero opened #21
  • Sep 24 2017 16:19
    paperplanes53 opened #81
  • Sep 20 2017 16:12
    cd-Zero opened #80
  • Sep 10 2017 11:21
    softmantk opened #20
  • Sep 09 2017 01:09
    cd-Zero edited #19
  • Sep 09 2017 01:09
    cd-Zero edited #19
  • Sep 09 2017 01:08
    cd-Zero opened #19
  • Aug 30 2017 20:23
    knappsacks opened #79
  • Aug 24 2017 18:58
    knappsacks opened #18
  • Aug 17 2017 23:19
    joshua-fogg opened #78
  • Jul 07 2017 16:16
    MiloATH opened #77
Hugo
@hugoender
@johnstonbl01 oh trust me I'm the same way. This is the first trip where I DIDNT want to go home.
Tyler
@teesloane
@hugoender !!!!
Wow japan! that sounds amazing!
jealous.
Would love to go someday.
I'm working contract right now. Feels good to be doing this stuff. I'm actually just starting to get into making some youtube tutorials as well!
(for code)
other than that, I'm spending my spare time working on open source projects, ahnging out with my roommates, and just enjoying Toronto.
@jondcoleman How've you been mang? Have you recovered from your surgery? (fingers crossed :) )
Hugo
@hugoender
@teesloane yeah Japan should be at the top of everyone's travel list! I'm glad to hear you're enjoying your work. Makes me jealous :p
I'm going to Canada in January
Whistler to be exact
Going skiing. I'm so freaking excited that I cannot contain myself. I hear that Canada is beautiful!
Arshad Khan
@arshdkhn1
actually I didnt see script tags in html files
Edwin Harly
@edwinharly
.findOne({ 'github.id': req.user.github.id }, { '_id': false })
I picked this line from clickHandler.server.js , is that user refer to our schema ?
Jonathan Coleman
@jondcoleman
This message was deleted
Yes. It is stored on the req object by passport.js @edwinharly
Edwin Harly
@edwinharly
@jondcoleman got it, thanks.
Edwin Harly
@edwinharly

Hi, just want to clarify a few things here.
I want to fetch articles data from database, and display it to the web page, so
I made a new articles model like this

var Article = new Schema({
    title: String,
    imgSrc: String,
    url: String,
    headline: String
});

Then, based on clickController and clickHandler , I also made articleController and articleHandler for the articles like these
articleController.client.js

'use strict';
(function () {
    var ulArtikel = document.getElementById('ulArtikel');
    var apiUrl = 'http://localhost:8080/api/:id/artikel';
    ajaxFunctions.ready(ajaxFunctions.ajaxRequest('GET', apiUrl, function (data) {
        var articleObject = JSON.parse(data);
        console.log(articleObject);
        for (var i=0; i<articleObject.length; i++) {
            var li = document.createElement('li');
            var node = document.createTextNode(articleObject[i].title);
            li.appendChild(node);
            ul.appendChild(li);
        }
    }));
})();

articleHandler.server.js

'use strict'
var Article = require('../models/articles.js');
function ArticleHandler() {
    this.getArticles = function (req, res) {
        Article.find().exec( function (err, result) {
            if (err) { throw err; }
            res.json(result);
        });
    };
}
module.exports = ArticleHandler;

and new routes for the article, like these

app.route('/artikel').get( function(req, res) {
        res.sendFile(path + '/public/kumpulanartikel.html');
    });
app.route('/api/:id/artikel')
        .get(isLoggedIn, articleHandler.getArticles);

The result is, it didn't work.
Am I missing something or some step here ?

Arshad Khan
@arshdkhn1
@edwinharly I suppose you are adding articleHandler.client.js script to your html file. Everything looks fine. What do you get in your console i.e., articleObject ? Please tell me what 's goin wrong once u find ur mistake.
Edwin Harly
@edwinharly
@arshdkhn1 I forgot to mention about it, but articleController.client.js has been included in the html file, not articleHandler.client.js, is that what you mean ?
Edwin Harly
@edwinharly

@arshdkhn1 I got this error msg on console:

Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at artikelController.client.js:17
    at XMLHttpRequest.xmlhttp.onreadystatechange (ajax-functions.js:21)

artikelController.client.js on line 17 is this
var articleObject = JSON.parse(data);
ajax-functions.js on line 21 is this
callback(xmlhttp.response);

Arshad Khan
@arshdkhn1
@edwinharly oh sorry i meant articleController.client.js
Arshad Khan
@arshdkhn1
@edwinharly remove JSON.parse and ur error wil go away
sc.png
@edwinharly If the response header is text/html you need to parse, but if the response header is application/json it is already parsed for you.
res.json under the hood sets response header as application/json
Arshad Khan
@arshdkhn1
You would have needed JSON.parse if you had send response via res.send without explicitly setting headers to application/json
Edwin Harly
@edwinharly
Screenshot from 2016-12-16 18:52:33.png
@arshdkhn1 I removed the JSON.parse and the error did go away, but the result from the database which I append to the 'li' element turns out like the image above
@arshdkhn1 and how surprisingly, when I print it to the console, it is my whole HTML file
Arshad Khan
@arshdkhn1
@edwinharly make a github repo and share url
Edwin Harly
@edwinharly
@arshdkhn1 well, it's working now, there's something with my login session, hence it returns my login page HTML instead of my db's result
@arshdkhn1 here is the link if you want to check it out https://github.com/edwinharly/sibatobata.github.io.git
Arshad Khan
@arshdkhn1
@edwinharly ok then fine
Edwin Harly
@edwinharly
Hi, another question here, how to send data using our current clementine xmlhttp POST request from client to the server ?
Edwin Harly
@edwinharly
another question (again), the apiUrl which contains /:id/ when did it get replaced by some object's id ? and is it possible to set this "id" value manually ?
Arshad Khan
@arshdkhn1
@edwinharly wrong group .. ask it on https://gitter.im/FreeCodeCamp/HelpBackEnd
Edwin Harly
@edwinharly
@arshdkhn1 OK, thanks.
ladiamont
@ladiamont
The only one
WiseKodama
@WiseKodama
Anyone alive here?
Blake Johnston
@johnstonbl01
@WiseKodama Yes
WiseKodama
@WiseKodama
@johnstonbl01 Hi Blake. I am pretty new to backend and I am going through the backend challenges on FCC, can you tell me what the pros of using Clementine compared to just Node are?
Blake Johnston
@johnstonbl01
For the backend challenges? Not a whole lot. I’d probably just used Node for those. Clementine is meant for backend + frontend.
Blake Johnston
@johnstonbl01
Ahh. So I’m just looking at the curriculum again. If you want to just use Node + browser, that works as well. Clementine is an example and starting point for you to build off of, and has frontend + backend code already in place.
The goal of which would be to save time, and show an example of how the pieces fit together. If that’s not helpful, or you want the experience of building it from scratch, then it’s totally fine to not use it.
Arshad Khan
@arshdkhn1
@johnstonbl01 clementine was very helpful when i made my first full stack project.. it surely teaches some very important concept to a beginner
Blake Johnston
@johnstonbl01
:thumbsup:
WiseKodama
@WiseKodama
It was the opposite for me, to be honest. I understood the code that was placed there. But it wasn't how I liked it so I decided to start from scratch. No offence I hope. I am excited to get into it later on but firstly I wish to finish the Backend challenges, strapped for time. :)
Dorothy Wegmüller-Ngudle
@GrannyCamper
Hi guys
Blake Johnston
@johnstonbl01
@GrannyCamper Howdy!