The display of temporary headers - Nodemailer - AJAX

I keep receiving a warning in the request header that says: Provisional headers are shown. I'm struggling to identify the root cause of this issue. This warning prevents the readyState from changing and my callbacks on the eventhandler onreadystatechange are not being triggered. I suspect the problem lies within the application/json request header, but so far, I haven't been able to find a solution. If anyone has any insights on how to resolve this, I would greatly appreciate it. Here is my AJAX Code:

export default function ajax() {
  const form = document.forms[0];

  const xhr = new XMLHttpRequest();

  form.addEventListener('submit', (e) => {
    e.preventDefault();

    // FORMDATA TO JSON OBJECT
    const fields = document.querySelectorAll('form > div');
    let formData = {};
    fields.forEach((container) => {
      formData[container.childNodes[0].name] = container.childNodes[0].value;
    })
    const formDataJSON = JSON.stringify(formData);

    xhr.open('POST', '/send', true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

    xhr.onreadystatechange = function() {
      if(this.readyState === this.DONE && this.status === 200)
        console.log('success');

      else if(this.readyState === this.UNSET)
        console.log('failed');

      else if(this.readyState === this.LOADING)
        console.log('loading');
    }

    xhr.send(formDataJSON);
  })
}

Nodemailer:

module.exports = (data) => {
  const _auth = require('./_auth');
  const nodemailer = require('nodemailer');

  const transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
      user: _auth.user,
      pass: _auth.pass
    }
  });

  const html = `
    <div style="background-color: #F3F4F7; border-radius: 10px; padding: 50px;">
      <h2>Sie haben eine neue Nachricht</h2>
      <p>${data.nachricht}</p>
      <h3>Absender</h3>
      <ul>
        <li>Name: ${data.name}</li>
        <li>Email: ${data.email}</li>
        <li>Tel: ${data.tel}</li>
      </ul>
    </div>
  `;

  const mailOptions = {
    from: data.email,
    to: _auth.user,
    subject: '20° - Nachricht',
    text: data.nachricht,
    html
  };

  transporter.sendMail(mailOptions, function(error, info){
    if (error) 
      console.log(error);
    else 
      console.log('Email sent: ' + info.response);

    transporter.close();
  });
}

Answer №1

insert header:

create config object with POST method and specified headers to send JSON data

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

Creating a visual representation of data using Google Charts to display a stacked bar chart

I wrote a script to display a stacked Google chart using JSON data stored on the wwwroot directory - <html> <head> <title>DevOps Monitoring Application</title> <link rel="icon" type="image/png" hr ...

jQuery causing YouTube object template to not display when links are added

After storing an object template in a variable, I am using jQuery to add video links. This is being done in preparation for adding the links into the object template through ajax in the future. However, the video is not appearing as expected and I'm ...

Locate MongoDB documentation pertaining to arrays of objects with two specific fields

For instance, consider a Mongo db collection: [ { "user_id": 1, "lead_id": 901, ... ... }, { "user_id": 2, "lead_id": 902, ... ... }, { "user_id": 2, & ...

Experiencing ERR_TOO_MANY_REDIRECTS while using Next.js with Vercel and a Custom Domain through Cloudflare

I'm having trouble getting my Next.js project set up on Vercel with a custom domain managed through Cloudflare. Despite configuring the DNS and SSL settings correctly, I keep seeing a net::ERR_TOO_MANY_REDIRECTS error when trying to access my site at ...

Can a snapshot be taken of an auto-generated ID document in FireStore?

Currently, I am working on developing both a mobile app and web app for my Final Year Project. As someone relatively new to Firestore, I am using a single instance of it to store data. When a customer registers through the mobile app, their information ge ...

What is the best way to pass a variable value from a JavaScript function to a Python function within a Django framework

My goal is to use HTML and JavaScript to scan a QR code in nurse_home.html. I have successfully scanned and viewed the content of the QR code on the website, but I am facing an issue with POSTing the QR code output represented by <output type='POST ...

Pass more information along with form_data using ajax

Firstly, I would like to showcase a demo illustrating the behavior that I am aiming to achieve. $('#multiple_files').change(function(){ var form_data = new FormData(); for(var i=0; i<files.length; i++) { form ...

Node.js offers a variety of routing options and URL endpoints

app.use('/api', require('./api')); app.use('/', require('./cms')); The initial path is designated for my public API, while the latter is intended for the CMS dashboard. However, the setup is flawed as localhost:80/a ...

What are the various categories for the ASP.NET AJAX accordion menu?

I have encountered an issue with my SQL tables, specifically Categories and Posts. When I try to select the top 5 records for each category and display them in an accordion menu, it shows the category names for each post repeatedly. Below is a snippet of ...

What is the best way to display index.ejs when the input field is blank?

If the input field is left empty when I click the form button, I want to redirect to "/". After clicking the button, the desired URL should be: http://localhost:3000 Header.ejs <form action="/search" method="GET"> < ...

Using a JavaScript if statement to check the height of a specific HTML element

I have been struggling to figure out how to insert an if-else statement in JavaScript that references data about an HTML element. My objective is to create an "onclick" function that enlarges an image with a 200ms delay and another function that returns th ...

Tips on modifying the maxlength attributes for all "field answer" class elements

Looking for some help with adjusting the "maxlength" attribute in a class called "field answer." The current maxlength is set to 250, but I need it changed to 9999. Can someone guide me through this process? <div class="field answer"> &l ...

Angular.js encountered an error at line 13550: [ng:areq] The argument 'popCntrl' is expected to be a function, but it was undefined

I have been diving into learning AngularJS on my own recently, and I've been attempting to create a basic popup feature. However, I keep encountering the error mentioned in the title. While searching for solutions, I haven't found any examples th ...

Retrieving an assortment of objects from a database and showcasing them using React

Attempting to retrieve an array of objects led me to this issue. Please excuse the messy code, I am still learning. export class App extends Component { state ={ character:[] } componentDidMount(){ fetch('https://swapi.dev/api/people/ ...

Tips for adding responses to input fields in AngularJS

I am looking to populate data into 3 inputs based on the JSON response I receive from my node server. However, despite receiving a response, I am unable to input it into the designated fields. Controller: $scope.edit = function(id, contact) { console.log ...

Steps to configure useState to manage data within an object

Having trouble setting an object with useState in my code. Despite my effort, I am only getting the initial value for the object named setWishlist. Can someone spot what mistake I am making? const CenterModal = props => { const [modalData, setModalDa ...

What is the method for configuring my bot to forward all logs to a specific channel?

const logsChannel = message.guild.channels.cache.find(channel => channel.name === 'logs'); I am looking to set up my bot to send log messages for various events, like member join/leave or message deletion, specifically in a channel named &apo ...

Make the default request by utilizing a function as the header

Is there a way to pass a function as a request header using the NPM request module's request.defaults API? I want the function's result to become the header value every time I make an outgoing request. For example: request.defaults({ header ...

Ways to navigate to a different page using HTML response from an AJAX request

After receiving an HTML document as a response from an AJAX call, I need to create a redirection page using this HTML response. Can anyone provide guidance on how to achieve this? ...

Explanation of JavaScript code snippet

fnTest = /abc/.test(function () { abc; }) ? /\bchild\b/ : /.*/; I am struggling to comprehend the functionality of this particular javascript snippet. Would someone be able to elaborate on the logic behind this code fragment? ...