transferring information between different views in express.js

I am completely new to the world of express and node, so please be patient with me :D

In my index.ejs file, I have a string that I need to pass to my viewActivity.ejs file. This string will be utilized in the JavaScript section of my viewActivity.ejs file. I am unsure of the correct approach to achieve this. Is it even possible to pass the string directly from one view to another, or do I need to involve another file?

Below is my code. I aim to pass the "stringToPass" to another view when a button is clicked.

function getPosts() {
    var query = new Parse.Query(Post);
    query.find({
        success: function(results){

            for (var i in results) {
                var title = results[i].get("activityTitle");

                var stringToPass = results[i].id


            }

        }, error: function(error) {
            console.log("Query Error:"+error.message);
        }

    });
}

Answer №1

From what I've gathered, express functions as the middleman for handling requests. For example, it can serve up a file or any other content based on the request it receives.

Once express has completed its job of handling the request, it doesn't keep track of what the client does with the response. After sending back the HTML or JSON file, any further actions will be taken care of by client-side scripts that communicate with the express server through additional requests. UPDATE: these client-side scripts can manipulate the DOM and trigger subsequent requests (like when a user clicks a submit button) that are processed by a different route.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Triggering a keyboard *ENTER* event on an Input in Javascript/React by clicking a button is a common query among developers

I am facing a challenge with an Input element that only displays results when I press Enter on the keyboard. The element is part of a third-party extension, so my control over it is limited. My goal is to trigger the ENTER event for the Input when a button ...

Which is the better choice for accessing and manipulating JSON files – using Ajax or the Node fs module?

When storing quiz questions using JSON data, should I use vanilla AJAX or Node.js file system to read the file? I am planning to develop a website where users can create quizzes and save them as JSON. I intend to utilize the Node.js fs module to save the ...

Implementing Bootstrap in Angular 2 using vanilla JavaScript/ES6: A step-by-step guide

Currently, I am in the process of developing an Angular 2 application without TypeScript and facing difficulties with bootstrapping it as I cannot find any relevant examples. My app, which does not include the bootstrap() function, starts off like this: ...

The entire React component is not rendering as expected when calling res.render in PugJS within Express

Seeking guidance for the following issue: I have developed a PugJS view that is rendered within an ExpressJS route. In the call to the ExpressJS function res.render, the React component is included as data inside the .render() function call.... The prob ...

Using PHP and XML with Ajax can run into problems with the getElementsByTagName function in Internet

Encountering a problem with getElementsByTagName specifically in IE versions 7 and 8. An address lookup generates suggested addresses as XML strings stored in a PHP session variable. These are then accessed using an AJAX function to retrieve the desired s ...

Discovering, storing, and displaying JSON data in JavaScript

I am currently working on a PHP file called rows2.php that displays results from a database by showing the new id of the field in this format: {'new_id':'92'} My goal is to use JavaScript to load this data and add the new_id surrounded ...

Combining Key-Value pairs in JavaScript using JSON

I am currently working on parsing a JSON object to extract the key and value combined into a variable. The desired output I want from the provided JSON is: "/" - 7.84 GiB; "/opt" - 4.86 GiB; "/usr" - 4.80 GiB While I can retrieve objects using my code sn ...

The type 'function that takes in a CustomEvent and returns void' cannot be assigned to a parameter of type 'EventListenerOrEventListenerObject'

When I upgraded from TypeScript version 2.5.3 to 2.6.1, my custom event setup started giving me an error. window.addEventListener('OnRewards', (e: CustomEvent) => { // my code here }) [ts] Argument of type '(e: CustomEvent) => ...

What is the best way to implement lazy loading of images that have not been downloaded in a JavaFX WebView?

Currently, I am in the process of developing an email client application using JavaFX WebView to showcase email HTML files. In order to enhance its responsiveness and speed, my goal is to display inline images in emails as they are downloaded locally. Duri ...

Vue.js does not support animation for the Lodash shuffle function

I'm having trouble getting the lodash's shuffle method to animate properly in Vue.js. I followed the code from the documentation, but for some reason, the shuffle occurs instantly instead of smoothly. When I tested the animation with actual item ...

I found that when using a variable with a dynamic value in a function, it is preventing me from successfully submitting a form through ajax

Many forms with different classes are present on a single page, each having two buttons to submit the parent form. The form submission occurs upon clicking either #avote_down or #avote_up. The script captures the class of the parent form of the clicked bu ...

When the user hits the enter key, automatically submit a form without the need for

Is it possible to submit a form on enter using type="button"? Here are my input fields: <input type="text" id = "login-user" class="form-control log-input" placeholder="Username" required="required"> <input type="password" id="login-password" clas ...

The X axis labels are missing on the Google column chart

Problem: All column charts are rendering correctly in Internet Explorer. However, Upon clicking the "View Build Performances" button, project names are displayed on the x-axis of the first three column charts only. The other column charts do not show pro ...

Extract Information from a Website

Is there a way to extract data from another website using JavaScript and save it into a .TXT or possibly an XML file? If JavaScript is not the best solution, I am open to other suggestions. I am specifically interested in extracting the price and item na ...

Issue with rendering Angular templates

Having just embarked on my AngularJS journey, I'm currently facing an issue with this specific code snippet. The following is an excerpt from my JavaScript file named cribsController.js: angular .module('ngCribs') .controller('cribsCo ...

In main.js within the Google Maps API, an error is triggered when trying to setDraggable(false) on a

Here's a piece of JavaScript code I'm working with: google.maps.event.addListener(mark, 'dragend',x(mark)); function x(mark) { mark.setDraggable(false); } Recently, when I try to move a marker to a different position, I encounter ...

Why does Material-UI TableCell-root include a padding-right of 40px?

I'm intrigued by the reasoning behind this. I'm considering overriding it, but I want to ensure that I'm not undoing someone's hard work. .MuiTableCell-root { display: table-cell; padding: 14px 40px 14px 16px; font-size: 0. ...

Three fixed position divs arranged horizontally side by side

I am attempting to organize 3 divs in a row using Flex. ISSUE 1: The div that is centered is set with position: fixed. However, the two other divs on each side do not stay aligned with the centered fixed div when scrolling. If I change the centered div to ...

Obtain the URL link from Unsplash where the picture is sourced

As I work on a website, I incorporate a link () to display a random photo. However, the photo refreshes periodically and upon loading the site, all that is visible is this default link: . Is there a method to extract the actual source like so: "". Althou ...

Implementing jquery document.ready() with <img onload> event

My current need is to trigger a JavaScript function each time an image loads on the page, but I also require that the DOM of the page is fully loaded before the script executes. I have provided a sample example below and would appreciate feedback on wheth ...