What is the best way to include an alert message in the res.writehead function of http node.js, specifically when using res.writeHead(301, { "Location": "/path/within/site" })?

      res.writeHead(301,  "<!DOCTYPE html>" +
      "<html lang='en' dir='ltr'>" +
      "<head>" +
         "<met charset='utf-8'>" +
          "<title>Hola Mundo</title>" +
        "</head>" +
       "<body>" +
         "<script type='text/javascript'>alert('DOne')</script>" +
     "</body>" +  "</html>", { "Location": "http://localhost:8086/uploadform" });

Instead of displaying the alert message first as expected, it is redirecting directly to the given link. I would like the alert message to be shown before being redirected.

Answer №1

If you want to achieve the desired outcome, consider wrapping everything in the script block:

 res.writeHead(301,  "<!DOCTYPE html>" +
  "<html lang='en' dir='ltr'>" +
  "<head>" +
     "<met charset='utf-8'>" +
      "<title>Hola Mundo</title>" +
    "</head>" +
   "<body>" +
     "<script type='text/javascript'>document.onreadystatechange=function(){alert('DOne')}</script>" +
 "</body>" +  "</html>", { "Location": "http://localhost:8086/uploadform" });

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

GDB does not support backtrace functionality, whereas LLDB does

In an experiment, I'm currently debugging a nodejs core dump. The goal was to simulate a production issue and analyze the V8 stack trace in a core dump. To achieve this, I deliberately wrote a piece of code in NodeJS that continuously performs string ...

Activate the class using Vue with the v-for directive

I'm curious about the v-for functionality. Why is it necessary to use this.activeClass = {...this.activeClass} to update the component? I noticed that the component does not update after this line of code. if (this.activeClass[index]) { ...

No translation or compiling of SCSS/SASS to CSS available

As a beginner Sass user, I am working on mastering the SMACSS hierarchy and incorporating it into my project using Brackets. However, I have encountered an issue with mapping the main.scss file to the main.css file even though it compiles successfully via ...

After integrating Redux into React, the map(item) function is unable to send "item" as props to a JSX component

Currently, I am working on integrating Redux into my React application. As part of this process, I have developed four actions to manage the "items" in my application. The initial three actions, namely GET_ITEMS, DELETE_ITEM, and ADD_ITEM, function seamles ...

Failed deployment of Node.js on Heroku results in the inability to serve static files

I have been attempting to implement two solutions I found, but they are not working as expected. The static files cannot be located. The following code is not working: process.env.PWD = process.cwd() app.set('views', path.join(process.env.PWD, ...

Toggle the jQuery class off when a different element is chosen

I've created a function that toggles a class to change the style of an element when it is selected. However, I'm facing an issue where the new style remains even when another element is selected. Is there a way to make the styling revert back to ...

Issue with Nav Bar Toggle not changing text to white color

Query I'm baffled as to why the text in the navigation bar (when opened with the Burger Menu) refuses to turn white. I've exhausted all efforts to change the color to white. Please assist me in pinpointing why the text remains unaffected when t ...

Exploring the Significance of jQuery in a Real-

I manage a large website with an extensive amount of jQuery code spread across multiple pages. The total codebase is around 1000 lines, well-optimized and excluding plugins. Despite jQuery being efficient in ignoring listeners for non-existent page elemen ...

Modify the stroke attribute of the <path> element using CSS

I have a generated svg path code that I want to customize using CSS to remove the default stroke. How can I override the stroke property and set it to none? code: <div class="container" style="position: absolute; left: 3px; z-index: 1;"> <svg he ...

What is the equivalent of specifying globalDevDependencies for npm @types packages in typings?

I am looking to update a project using tsc@2 and remove typings from my toolchain. Updating common dependencies is easy as they are listed in my typings.json file: "dependencies": { "bluebird": "registry:npm/bluebird#3.3.4+20160515010139", "lodash": ...

Tips for altering an element's style attribute using ERB and JQuery while including a % symbol within the value

I'm attempting to adjust the style="width: 5%" attribute of a span using Jquery and AJAX. This width needs to be specified in percentage as it represents a progress bar. Here is my code snippet from html.erb: <div class="progress success round" ...

Uploading images in React JS by allowing users to paste images

Currently working on a chat application using React JS and I'm looking to enable image uploading when an image is pasted into the chatbox. How can I make this happen? Essentially, I am in need of: An event that will activate upon performing the "Pas ...

Overlap of Table Borders

Check out this example: http://jsfiddle.net/qTjdX/ I am trying to make the red border-bottom display as one solid line, but currently the yellow border is breaking it up into three parts. Is there a way for the border-bottom to take precedence? Perhaps u ...

Switching from Dom to Jquery

Seeking assistance to convert DOM values into Jquery equivalent. For instance, how can I translate the DOM code: var x = document.querySelector('#x'); into Jquery format? Any suggestions? Additionally, looking for guidance on transforming even ...

Invoking code behind functions through ajax requests to dynamically display items one by one

I'm currently working with calling code behind functions from an ajax call. I have recently developed a method called Post, which returns a list of values. My goal is to verify these values from the client side by displaying them in an alert message. ...

Scrollable Container in EaselJS

Is it feasible to implement vertical scrolling (panning) using touch on an Easeljs container that contains rows of buttons taller than the screen height? Picture a container that spans the width of the device and occupies about 80% of the height, positio ...

Extract core object from array of objects with lodash or javascript

In my code, I have an array of objects that each contain a base object with a set of values. My goal is to remove the base object from all the data and achieve the Expected result shown below. Here is an example of the array: [ { "100": { ...

What is the best way to compare two arrays that have elements of different data types?

Can someone help me compare two arrays in TypeScript to see if they are identical? I'm having trouble with the current code. Here's what I have: let props:(string|boolean)[]=['abc','def',true,false,'xyz'] let propsCo ...

Adding space and arranging the cards in a horizontal layout using Bootstrap

I'm working on a code and an HTML page with Bootstrap enabled. The current setup simply displays three bootstrap cards with images vertically on the page. Now, I would like to: a) Add a margin from the left-hand side. b) Display the cards horizontal ...

Error Message When Attempting to Load JQuery Library

Currently experimenting with PHP, JavaScript, and jQuery tutorials, I encountered the following error. The tutorials can be accessed here Below is the error message from the Chrome browser console: Failed to load resource: net::ERR_FILE_NOT_FOUND auto- ...