Received net::ERR_EMPTY_RESPONSE error when making an AngularJs POST request

My specific header request

Request URL:http://demo7876167.mockable.io/auth/login
Request Headers
Provisional headers are shown
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Origin:http://localhost:8000
Referer:http://localhost:8000/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:CACC0804-7333-424B-985E-DBA8164A45E1

This error message displays in console

OPTIONS http://demo7876167.mockable.io/auth/login net::ERR_EMPTY_RESPONSE

Interestingly, the same URL functions properly when accessed through Postman. This issue arises whenever I attempt to access a different server.

Is there a specific approach in AngularJS to execute calls so that I can send requests to any CORS-enabled server?

Answer №1

Before executing the POST request, the browser is sending a preflight OPTIONS request. This step is necessary when dealing with non-simple requests, such as the one you are testing in Postman.

In Angular, data in POST requests is automatically encoded as JSON by default. However, JSON encoding is not accepted for simple requests according to HTTP standards.

The server must respond to the OPTIONS request from the browser to authorize the subsequent JSON Encoded POST request in your JavaScript code.

Once permission is granted, the browser will proceed with the POST request that you are emulating in Postman.

Alternatively, consider making a form-encoded POST request instead of JSON encoding. This can be achieved by following this guide.

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

What could be the reason for my Bootstrap popover malfunctioning?

I've been attempting to incorporate the Bootstrap popover into my project. I copied the code exactly from the example provided on the website, but unfortunately, it doesn't seem to be functioning properly on my site. Below is the full code snippe ...

Utilize a blob as the source image

I have a system where I am storing images as blobs in my MySQL database. I have set up a node API to retrieve the data from the database and display it using JQuery Ajax : $.ajax({ url: "http://mydinners.fr:5280/partner", type: "GET", dataty ...

Acquiring the index of a selector event within a list of dynamic elements

I am seeking guidance on how to go about solving the issue of obtaining an event index. I have a hunch that closures might play a role in the solution and would appreciate some insights. Initially, I dynamically build an HTML5 video container using an aja ...

"Guidance on jQuery syntax: Use a textbox to filter out and hide select options with each keystroke

Is there a way to modify my existing code so that it can show or hide elements based on a filter condition, specifically for Internet Explorer? I want to wrap the unmatched elements in a SPAN tag and hide them if the browser is IE, and vice versa by remo ...

Experiencing difficulties with the ng-click directive in AngularJS

Trying to solve a coding dilemma with two buttons - one that triggers a click event redirecting to the login page, and another button meant for displaying a pop-up. Strangely, clicking on the second button also ends up directing me to the login page. This ...

Exploring the functionality of placeholders within jQuery

I am trying to create a customizable text template where I can insert placeholders and then fill those placeholders with data to use on my page. For example: var template = '<div class="persons">'; template += '<p> <span clas ...

What is the process for showcasing a local notification within my application?

Here is the code snippet I am working with: import { LocalNotifications } from '@ionic-native/local-notifications'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scs ...

Continuous animation for a sequence of overlapping images with smooth transitions

Currently, I am in the process of developing a JavaScript script that will cycle through a series of images within the same <div>. The goal is to create a seamless animation effect with the image transitions. Although the images are cycling through, ...

Having trouble extracting the POST value from a form in PHP sent via jQuery AJAX

I need help with sending data from an ajax form and receiving it using PHP. I encountered the following error: Notice: Undefined index: numer in C:\xampp\htdocs\testajax\dalej.php on line 2. Here is the script for loading pages in ind ...

Users are reporting a problem with the PrimeNG confirmation dialog where it becomes unresponsive and locks up the screen

Previously functioning code seems to have been affected by an update to PrimeNG. The confirmation dialog that was once usable is now hidden behind a gray click-mask, rendering everything on the screen unclickable: https://i.sstatic.net/YN7Iu.png The HTML ...

Can javascript be used to swap out the folder in my URL?

I have been searching for solutions on how to change the language of my website using jQuery, but so far I have not found anything that works for me. Let's take my website as an example: www.domain.com I have separate folders for different languages. ...

What is the process for exporting an NPM module for use without specifying the package name?

I am looking for a way to export an NPM module so that it can be used without specifying the package name. Traditionally, modules are exported like this: function hello(){ console.log("hello"); } module.exports.hello = hello; And then imported and ...

The Node.js callback is executed before the entire function has finished executing

const fileSystem = require('fs'); const filePath = require('path'); module.exports.getFiles = function(filepath, callback) { let files = []; fileSystem.exists(filepath, function(exists){ if(exists){ fileSy ...

Serialization of JSON data in JavaScript and how it can be deserialized in PHP

Hey there, I'm struggling with deserializing JSON that was serialized in JavaScript. On my webpage, I have a form where each row represents a product (with various inputs, selects, and checkboxes): name, price, total_count, ... name2, price2, total_c ...

Guide to deleting a user from a list in AngularJS

I created a confirm button to delete a user from the list, but for some reason it's not working. Could someone please review my JavaScript code to see if there are any mistakes? Here is the JavaScript code: $scope.doDelete = function(user) { ...

Issues with Tooltips and Popovers in Bootstrap 5

I recently built a small website using Bootstrap 5. On this site, I added 2 buttons at the bottom of the page with tooltips and popovers. However, they seem to be malfunctioning as nothing is being displayed. You can check out the site for yourself at th ...

What is the best way to set values for the outcomes of a jQuery/AJAX post?

When sending data to a php page using jquery, I aim to receive the response from the page and store it in php variables on the original page without displaying results in the HTML or appending a DIV. Here's an example of how this can be achieved: Sam ...

Transforming a sophisticated nested array containing named values into JSON format

I am facing a challenge with converting an array into JSON format. The array, named classProfiles, has the following structure (seen after inspecting console output): Buildings_clear: Array(0) band1: [Min: 24, Max: 24, Mean: 24, Median: 24, StdDev: 0] ...

Creating a Related Entry in strapi v4: A Step-by-Step Guide

Whenever I try to add a new record in my Collection-Type, all the field values are successfully added to the new entry except for the value in the field with a Relation type. For instance, in my event Collection-Type, I have fields like name, performers, ...

Struggling to make Radio Buttons function properly within an ng-repeat loop while using font-awesome icons as labels

I am facing some difficulties with implementing Font Awesome icons for radio buttons in an AngularJS ng-repeat. I have tried different solutions that involve using $parent within the ng-repeat, but none of them have worked for me so far. It is important fo ...