\' + data[\'result\'] + \' \'); $(\'#input\').val(\'\'); // reset the textbox })
ID: 3833160 • Letter: #
Question
' + data['result'] + '
'); $('#input').val(''); // reset the textbox }) .fail((xhr) => { alert('Problem contacting server'); console.log(xhr); }); }); });
Hello, from Node!!
'); res.render('index', {title: 'NameSurfer'}); }); // Name surfer end point app.get("/namesurfer", (req, res) => { let input = req.query.text; NameSurfer.findOne ({name: input}, (err, rec) => { if (err) { console.log(err); res.json( {result: '***DB ERROR***'} ); } else if (rec == null) { res.json( {result: '***DB ERROR***'} ); } else { res.json( rec ); } }); }); // catch 404 and forward to error handler app.use(function(req, res, next) { let err = new Error('Not Found'); err.status = 404; next(err); }); // error handler app.use(function(err, req, res, next) { // set locals, only providing error in development res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; // render the error page res.status(err.status || 500); res.render('error'); }); module.exports = app;
CSV file(data):
Name Surfer Name undefinedExplanation / Answer
Hey there,
How are you the problem was, you were sending this:
$.get('/'+ name, { text: text }); on line 8 of you NameSurf.js. You were making a request to the root page because the variable name is undefined.
You should do this:
$.get('/namesurfer', { text: text });
Edit:
Tried to put this in comments but it's not taking code properly!
Change Line 107 App.js to
res.json({ result : rec });
and line 10 NameSurf.js to
$('#results').prepend('<li>' + data['result']['name'] + '</li>');
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.