Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on 

How do you reload this page / popup in Node?

Here's where my user starts:

User generated image
They click on the pencil and they get this pop up:

User generated image
After they finish updating their record, they get a popup that says, "Good job!" I'm working on that now.

But how do I refresh the screen they're looking at?

I can't reload the page because that eliminates the window they're looking at.

How do you do it?
Node.jsJavaScript

Avatar of undefined
Last Comment
Chris Stanyon
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

ASKER

Chris, this is awesome!

But...

I'm getting an undefined" for my "resp.data.activity.notes" etc.

When I do a console.log(resp), I get Object Object.

Here's my code:


router.post('/companies/update-activity', async (req, res) => {

    try {
        let _data = {
            notes : req.body.notes,
            date : req.body.date,
            company : req.body.company,
            type : req.body.activityType
        }
      
      console.log(_data.notes);
      console.log(req.body.activityId);

        Activity.model.updateOne({ _id: req.body.activityId }, {
         $set: {
         // set up the data you want to persist to the DB
         meta : {
            notes: _data.notes,
            date: _data.date,
         },
         type: _data.type,
         }
        },
      { runValidators: true }, (err) => {
            if (err) {
                console.log(err)
                return res.send(Activity.error('Sorry! Something went wrong! Try again!'))
            }
            res.send(Activity.success({notes: "hello"} ))
        });


    } catch (err) {
        res.send(Company.error(err))
    }

This: res.send(Activity.success({notes: "hello"} )) was just me fooling around with some different ideas.

What am I missing?
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

If you just send this back:

res.send(Activity.success({notes: "hello"} ))

Then you'll only have access to that as resp.data.notes

If you want to send a full Activity back, then you need to do this:

let activity = ... // make sure this is a fully populated activity (built or queried)
res.send(Activity.success({activity: activity} ))

Where the second acticity in the coed above is a variable holding a fully populated activity. The you resp will have an activity property and that property will have the relevant proeprties from the activity (phew - so many activities, I need a lie down!)

resp.data.activity.notes;
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Excellent.

On the Delete question, have you tried the code already posted - Leakim looks like he's got a handle on that one but I'll keep an eye on it.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo