Upon resolving cross-origin resource sharing issues, an AJAX call from a virtual server resulted in a HTTP 500 error, indicating that the

Trying to send a POST request to a Linux server from a Windows 7 virtual machine using VirtualBox was initially met with CORS issues. To resolve this, I installed the 'Allow-Control-Allow-Origin:' Chrome extension '*'. The CORS problem was fixed, but now I am seeing the message: "POST http://servidor.hanbai:8081/api/aa/v1/pedidos 500 (Request failed.)"

In addition, there is a warning about Cross-Origin Read Blocking (CORB) blocking the response from with MIME type application/vnd.sun.wadl+xml. More details can be found at .

Interestingly, when testing with POSTMAN, no issues arise. Any idea what might be causing this?

function sendToHanbai(order) {
console.log(order);
let createdOrderUrl;
$.ajax({
        type: "POST",
        url: "http://servidor.hanbai:8081/api/aa/v1/pedidos",
        data: JSON.stringify(order),
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',

        },
        success: function(data, status, request) {
            console.log(data);
            console.log(status);
            console.log(request);
            createdOrderUrl = request.getResponseHeader('location');
            console.log(createdOrderUrl);
            const regex = /(?<=pedidos\/).*$/gi;
            let match = regex.exec(createdOrderUrl);
            let createdOrderId = match[0];
            console.log(createdOrderId);
            renderSuccessDivWithCreatedOrder(createdOrderId);
        },
        error: function (data, status, request) {
            console.log(data);
            console.log(request);
            console.log(status);
            console.log("Error sending order to Hanbai");
        }
});
}

Answer №1

Don't rely on the Chrome extension for CORS, check out this helpful guide on adding headers to your server instead (https://www.w3.org/wiki/CORS_Enabled). To fix the error, consider including a dataType parameter in your ajax call and specify the data. Additionally, you can use Fiddler for debugging purposes. Hopefully, this advice proves useful.

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

Unraveling Nested JSON with Redshift and PostgreSQL

Attempting to extract 'avg' from a JSON text through the use of JSON_EXTRACT_PATH_TEXT() function. Here is a snippet of the JSON: { "data":[ { "name":"ping", "idx":0, "cnt":27, "min":16, ...

Error message in Node.js: Unable to establish connection to 127.0.0.1 on port 21 due to E

I am currently developing a simple application using node js, and I have encountered the following issue: Error: connect ECONNREFUSED 127.0.0.1:21 at Object exports._errnoException (util.js:1034:11) at exports _exceptionWithHostPort (util.js:1057: ...

Code in JavaScript often includes the use of variables to store and manipulate data

Do these blocks of JavaScript code serve the same purpose? // First Code Sample var first = prompt("Enter the first number:"); var second = prompt("Enter the second number:"); var sum = Number(first) + Number(second); alert(sum); // Second Code Sample ...

What is preventing me from excluding the implicit parameter in this situation?

Here is how my code looks: def okJsonify[T](data: T)(implicit tjs: Writes[T]): Result = Results.Ok(toJson(data)(tjs)) The definition of toJson can be found in play-json_2.11-2.3.7-sources.jar!/play/api/libs/json/Json.scala def toJson[T](o: T)(implic ...

What is the best method for transforming an array of strings into a JSON string in Hive?

My hive table test_tbl contains a string field tag_score, which includes JSON strings separated by ";": ---------- tag_score | -------------------------------------------------------------------------------- {"keyword":"abc",& ...

Converting a DataTable to JSON in Powershell v3 - Step-By-Step Guide

I have a DataTable named $dt containing data. In Powershell v3, I am interested in piping this data to JSON using the cmdlet ConvertTo-JSON. $ds.Tables["mytable"] | ConvertTo-Json However, when I run this command, all properties of the DataTable are ret ...

My component reference seems to have gone missing in angular2

Trying to load my Angular 2 app, I encountered this error: https://i.stack.imgur.com/FmgZE.png Despite having all the necessary files in place. https://i.stack.imgur.com/kj9cP.png Any suggestions on how to resolve this issue? Here is a snippet from ap ...

Exploring how to retrieve the input value from an element with ReactJs

Is there a way to determine if an input field contains a value by referencing another element? Here is my approach: <div className='input-item'> <input ref="accessKey" name="username" className="lci-text" type="text"/> & ...

Emphasizing Ajax in our open-source project

Is there a convenient wrapper for handling AJAX requests? If so, could someone recommend the top choice? ...

`Is it possible to retrieve data in Hindi and Gujarati from a MySQL database?`

After trying various solutions below my code, I found that it did not work. I have provided utf8_unicode_ci for Hindi and utf8_bin for Gujarati language in the database collation. I need help with fetching data in Hindi & Gujarati languages. <meta ...

Transmitting HTML and CSS code to the server for seamless conversion into a PDF file

I recently started using a tool called GemBoxDocument that allows me to convert HTML files into PDFs. Their website provides sample code demonstrating how to convert an existing file on a server (source): using System; using System.Linq; using System.Tex ...

With TypeScript, you have the flexibility to specify any data type in the generic types when using the axios.get method

axios.get('/api') When working with TypeScript as shown above, it is important to designate types for better clarity. This allows us to reference the type definition of axios, like so: (method) AxiosInstance.get<any, AxiosResponse<any> ...

Enhance your Rails Turbo render_async feature by incorporating JWT authorization into asynchronous requests

In my Rails app, I am utilizing render_async along with turbo-rails and I am attempting to include a JWT in the render_async request header. Within my application.rb file, I have the following configuration: RenderAsync.configure do |config| config.turb ...

Building objects utilizing Angular 2 and Ionic 2 form

Let's take a look at the ts file import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import { SalePage } from "../sale/sale"; import {Md5} from 'ts-md5/dist/md5'; import { ...

Why is my MySQL query not returning the most recent results when using setInterval()?

I am currently facing an issue with the setInterval function within the $(document).ready(function(){} My approach involves using setInterval to call a PHP script that executes MySQL queries to check the status of 4 switches and then updating the screen w ...

Managing numerous API requests in React Native

As I work on implementing a search field, I've encountered a challenge. Whenever a user enters text in the search field, a timer resets to 300 ms before an API call is sent to fetch autocomplete results. After receiving these results, the app then wai ...

Display HTML tags on an HTML page using TypeScript

In my angular application, I encountered an issue where I needed to call one component inside another component. Initially, I was able to achieve this by simply using the second component's selector in the HTML of the first component: html: <div&g ...

Automatically use JavaScript to send an email to my email address

I have a question I'm trying to solve: Is there a way to send myself an email notification (using a different address) when a specific event occurs in Javascript or Node.js? For example: if (100 > 90) { emailto="xxxxx.gmail.com" subject="It happ ...

How to Transfer Data from SuperAgent Library Outside the .then() Block?

I have a dilemma in my Nodejs project with two interdependent files. The key to this issue lies in the usage of a crucial library known as SuperAgent (I need it) Check out SuperAgent Library Here In file1.js const file2 = require('./file2'); ...

How to incorporate click and drag feature for rotating a 3D object using vue.js

Whenever I click a button, the rotation function is activated and allows me to rotate an object by hovering over it with my mouse. Now, I want to modify this behavior so that the object rotates only when I click on it and move the mouse (while holding dow ...