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

How can I efficiently pass a JavaScript object to a function using jQuery syntax?

Recently, I've delved into the world of JavaScript and started exploring object orientation, prototyping, and using objects for all functions and variables. However, there is one aspect that many frameworks like jQuery or extJS have that I struggle wi ...

Tips on triggering an AJAX call to load additional content when a user reaches the bottom of the page for the first time

My goal is to dynamically append an HTML file to a div element when the user reaches the bottom of the page. However, I have encountered an issue where the script appends the content multiple times after refreshing the page. It seems like the Boolean varia ...

Is an Ajax powered loading feature used in transitions between pages?

I recently came across this interesting website: It appears that they have implemented a clever technique where new content is dynamically loaded using AJAX, giving the impression of seamless navigation. Additionally, they have succeeded in hiding the bro ...

vee-validate - Standalone form validation with distinct procedures

I currently have a situation where I am dealing with two forms, each in separate steps and having their own submit button. Using $validator.validateAll() validates all the inputs on the page, but I specifically need validation for each form individually. ...

Tips on simulating the Q functions during unit testing in node.js using mocha and rewire!

Struggling with an issue while writing unit tests for node.js. The original code in my file is: var Q=require('q') . . . return Q.all(promises).then(function(data) { _.each(data, function(data) { checking.pu ...

Using an ng-repeat directive alongside an if condition in Angular

My website contains a vast array of 30 articles, previously represented by around 300 lines of HTML code, but now condensed to just 10 lines with angularjs. However, certain articles hold special significance and require specific display criteria. Check ou ...

Unable to locate "Gruntfile.js" Node module for task execution

I am currently in the process of developing a module that enables node to execute Grunt tasks via the command line. This Node module is globally installed at : C:\Users\pcharpin\AppData\Roaming\npm\node_modules\task-app ...

Troubleshooting Proxy.php issues in conjunction with AJAX Solr

Attempting to access a Solr 4.5.0 instance located on a private server, http://12.34.56.789:8983/ The application resides at this web server address, http://www.mywebapp.com To facilitate accessing the JSON object within the Solr instance, I decided to ...

The Architecture of a Node.js Application

I'm curious about the efficiency of my nodejs app structure in terms of performance optimization. My main concern lies in how I handle passing around references to my app object across modules. Basically, in my app.js file, I define all my dependenci ...

Is your JavaScript function failing to execute properly?

Within my script, I have defined two JavaScript functions: myFunction() and submitForm(). <script> var intervalID = 0; function myFunction(interval) { if(interval == 1) { if(intervalID != 0) { window.clearInterval(intervalID); in ...

CSS changes triggered by JQuery are ineffective

Having trouble modifying the CSS of a class in my HTML file. I've been struggling with this for quite some time and can't figure out what I'm doing wrong. (I've already attempted multiple versions, but nothing seems to work) Here' ...

Transmit text from tinyMCE through AJAX in MVC architecture with PHP

I am currently facing an issue while trying to send POST data in the form of an array containing email elements such as subject and message. The problem arises when using tinyMCE for the subject part, which is not being sent through successfully. All other ...

Implement unobtrusive JS in Rails with jQuery to update separate sections of the page simultaneously

When a user clicks on a sorting link within my blog, I intend to utilize AJAX in order to fetch new posts and update the sorting link section simultaneously. While this process could be simplified using RJS, I prefer to maintain unobtrusive JavaScript and ...

"Creating a duplicate of an element by utilizing the `next`

I have a dilemma involving two divs within a section of my project - one div is dynamically created while the other exists statically. My goal is to transfer the non-dynamically created div into the one that is generated dynamically. let adContainer = $ ...

Warning: Potential critical dependency detected while utilizing react-pdf package

When attempting to showcase a PDF on my react application, I encountered the following warning: /node_modules/react-pdf/node_modules/pdfjs-dist/build/pdf.js Critical dependency: require function is used in a way in which dependencies cannot be static ...

Adjust the shopping cart contents based on updated spinner values

Currently, I am working on an application that features a shopping cart with a DataTable. Within the cart, there is a spinner to indicate the quantity of each product. I want the shopping cart to refresh whenever the value of the spinner changes. Below is ...

Determine in Jquery if all the elements in array 2 are being utilized by array 1

Can anyone help me figure out why my array1 has a different length than array2? I've been searching for hours trying to find the mistake in my code. If it's not related to that, could someone kindly point out where I went wrong? function contr ...

Accessing the property of the scrollbox in Reactjs: How to get the horizontal offset

I am currently working on a scroll view designed as a series of views wrapped horizontally within a container. <div id="scroller" ref="scroller" onClick= {this.onClick.bind(this)} onMouseMove={this._onMouseMove.bind(this)}> {t ...

Dynamically Loading External JavaScript Files Depending on User Input

Looking for guidance on how to dynamically load a single javascript file out of several options based on user input in an HTML code. Any suggestions on how to achieve this task? Thank you! ...

Class component proceeding without waiting for function completion

My function, getactivity(), pulls and sorts data from an API and returns the sorted data in answer1 format. However, I am facing a problem where whenever I run the function to retrieve the data, it keeps returning nothing. Here is the full code: import Re ...