Error: The request does not have the 'Access-Control-Allow-Origin' header

As a beginner in post requests, I've been encountering an error when attempting to make a post request. Despite searching for solutions, the answers are too complex for me to grasp how to adjust my code to resolve it.

var url = 'http://unturnedbox.clanservers.com/serverquery/serverQuery.php';
$(document).on('click','.test', function(getServerInfo)
{
   var getServerInfo =
   {
        "ip": "23.229.5.250",
        "port": "27021"
    }

    $.post(url, JSON.stringify(getServerInfo), function(response)
    {
        response.addHeader("Access-Control-Allow-Origin", "http://unturnedbox.clanservers.com");
        if (response.error)
        {

        }
        else
        {
            $('.test').html('<div>'+ response.result.length +'</div>');
        }
    });
});

I would greatly appreciate it if someone could explain what mistakes I may be making. Thank you.

Answer №1

It is not possible for you to manually set the "Access-Control-Allow-Origin" header in your javascript code. This header is determined and added by the web server handling the post call.

The server hosting "" needs to be configured to include the appropriate access control header with the domain or address of your webpage, rather than you trying to set it from your end.

For instance, if your website is located at , then the server should respond with the header "Access-Control-Allow-Origin: ".

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

Can dark mode be activated and maintained across multiple pages using just one JavaScript file?

I'm facing an issue with maintaining a dark mode across multiple web pages. I tried adding a JavaScript script to all my HTML files, but it didn't work as expected. Then, I experimented by adding the script to just one HTML file, and while it suc ...

Updates to class variable values in jQuery are failing to take effect

Attempting to create my first JavaScript class has presented some challenges, specifically when it comes to updating a class variable. Despite hours of testing different approaches, I still can't seem to get it right! function ClassName(productId) { ...

Manipulate data with Jquery Serialize

There are multiple text boxes, drop down menus, and radio options on this form. Upon clicking submit, I need to save all the information entered by the user in order to store it into a database. <div id="reg2a"> First Name: <br/><input type ...

Next.js: An absence of response is observed when a high volume of requests is made on a server-side rendering page with

Currently, I am utilizing Next.js along with a custom server (express js) as demonstrated in the GitHub example. For instance, I have a page located at “/post/[id]” that makes use of Next.js dynamic routing. The issue arises when the number of request ...

An online submission form for sending information to an email address and receiving a notification email

I've been searching for a solution to my issue extensively, but I still can't seem to make it work. The problem lies in the form functionality on my website - it collects user data and sends it to me via email upon submission. Additionally, I wa ...

Laravel 8 - sweet alert functions properly, however, the ajax functionality is not functioning as expected

As a newcomer to Ajax, I am facing an issue with deleting records from the database using Sweet Alert2. Although my swal is working fine, the ajax function seems to be malfunctioning. Can anyone point out where the problem might be and suggest a solution? ...

Create text that alternates between blinking and changing content simultaneously

I'm currently working on a website and I am curious about how to achieve the effect of making text blink and change content simultaneously, similar to what is seen on this particular website . Sorry for not being more specific in my question. Thank yo ...

The enduring lifespan of an Android web page session

I am looking to display telemetry data from a web server on an HTML page using AJAX, without the need to create a native Android application. My goal is for the Android browser to continuously show the HTML page without going into sleep mode. Are there a ...

Guide to displaying API data in HTML format

This university assignment involves working on a homework project where I need to utilize a public API in HTML. So far, I have successfully called the public API to display a list of radio channels in the left menu (without adding any click functionality). ...

Simple Mobile-Friendly Tabs - mobile tabs are always visible

My JavaScript skills are not the best. I have been using Easy Responsive tabs and encountered an issue on the mobile version where clicking does not hide content, but only removes the "d_active" class and adds it to another element. I believe that if the ...

Sending data from child components to parent components in Angular

I'm facing an issue with retrieving data from a child array named store within user data returned by an API. When trying to access this child array in my view, it keeps returning undefined. Code export class TokoPage implements OnInit { store= nu ...

PHP and AJAX: Handling the 'Undefined Index' Error

As a newcomer to AJAX, I apologize if the solution is obvious. I need to insert dates into a MySQL table without having to refresh the page, but I'm encountering an issue. The code is throwing the following error: "Notice: Undefined index: post in ...

"Error encountered when making a request to Google API using Ember.js, response remains

Trying to fetch place suggestions from Google API using Ember js. Below is the code snippet for the service module: fetch(){ let url=`https://maps.googleapis.com/maps/api/place/autocomplete/json?input=IL&types=geocode&key=API_KEY` return Ember.RSV ...

What is the best way to showcase the outcome on the current page?

This is a sample HTML code for a registration form: <html> <head></head> <body> <form id="myform" action="formdata.php" method="post"> username:<input type="text" name="username" id="name"><br> password:&l ...

Angular 6 - The state of the expression was altered after it was verified, different types of constructions

During the build process in debug mode with ng build, I am encountering errors in some components. However, when I switch to production mode using ng build --prod, these errors disappear. I am curious as to why this discrepancy is occurring. Error: Expre ...

Converting a TypeScript object into a JSON string

When working with TypeScript, I am facing a challenge while trying to initialize an object that requires a JSON string for the "options" parameter. Specifically, it pertains to the object mentioned here. It is crucial that the options parameter be in JSON ...

Exploring Data within Data Structures

I am currently making two JSON requests in my code: d3.json("path/to/file1.json", function(error, json) { d3.json("path/to/file2.json", function(error, json2) { }); }); The structure of json 2 looks like this: [ { "city" : "LA", "locati ...

Retrieving information from a Rowdatapacket with expressjs

Is there a way to use a loop to retrieve a single value from each row in RowDataPacket? Currently, my results look like this: [ RowDataPacket { id: 522, number: '111', test: 'testing' }, RowDataPacket { id: 523, number: '112' ...

ReserveYourSpot: Effortless Seat Reservation with AngularJS at the Click of a Button [GIF]

ReserveYourSpot: An innovative AngularJS application designed to streamline the process of reserving seats for a movie show, similar to popular platforms like BookMyShow. https://i.stack.imgur.com/PZk1I.gif Interactive User Functions (Use Cases): A ...

Issue with Javascript/Jquery functionality within a PHP script

I have been attempting to incorporate a multi-select feature (view at http://jsfiddle.net/eUDRV/318/) into my PHP webpage. While I am able to display the table as desired, pressing the buttons to move elements from one side to another does not trigger any ...