Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:36:41+00:00 2026-05-29T22:36:41+00:00

I have the following node.js server set up listening to port 9001 var https

  • 0

I have the following node.js server set up listening to port 9001

var https = require('https');  
var fs = require('fs');  
var qs = require('querystring');    
var options = {  
  key: fs.readFileSync('privatekey.pem'),  
  cert: fs.readFileSync('certificate.pem')  
};  
https.createServer(options, function (req, res) {  
  res.writeHead(200);  
  console.log('Request Received!');  
  console.log(req.method);  
  if (true || req.method == 'POST') {  
    var body = '';  
    req.on('data', function (data) {  
      body += data;  
    });  
    req.on('end', function () {  
      console.log(body);  
      var POST = qs.parse(body);  
      console.log(POST);  
    });  
  }  
  res.end("hello, world\n");  
}).listen(9001);

and I am trying to get this server to respond to an AJAX call

function form_save()  
{  
  console.log("submitted!");  
  var data_obj = {  
    data1: "item1",  
    data2: "item2"  
  }  
  $.ajax({  
    url: 'https://adam.testserver.com:9001/',  
    type: "POST",  
    dataType: "json",  
    data: data_obj,  
    success: function() {  
      console.log("success!");  
    },  
    complete: function() {  
      console.log("complete!");  
    }  
  });  
}

There are two problems occurring with my arrangement. The first is that if I start the server and then click the button that triggers my form_save() the node server does not respond and I get the following error:

submitted!
OPTIONS https://adam.testserver.com:9001/ Resource failed to load
jQuery.extend.ajaxjquery.js:3633
$.ajaxjquery.validate.js:1087
form_savew_worksheet.php:64
confirm_deletew_worksheet.php:95
jQuery.event.handlejquery.js:2693
jQuery.event.add.handlejquery.js:2468
w_worksheet.php:73
complete!

At this point if I access that url directy (https://adam.testserver.com:9001/) I get the expected “hello, world” output as well as the console message “Request Received!
GET”. From this point on if I click the button to trigger my AJAX call I get a new error.

submitted!
XMLHttpRequest cannot load https://adam.testserver.com:9001/. Origin
https://adam.testserver.com is not allowed by Access-Control-Allow-Origin.
w_worksheet.php:73
complete!

I don’t understand why I get this message as both my form and node server reside on the same server. Thanks for taking the time to read, I appreciate any help I can get on this. I’ve been stuck for a while now!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:36:44+00:00Added an answer on May 29, 2026 at 10:36 pm

    You’ve run into the Cross-Origin Resource Sharing (CORS) specification.

    Note the OPTIONS in your output. The OPTIONS HTTP Verb is used by the browser to query the web server about the URL, not to GET its contents or POST data to it.

    Your server doesn’t respond with the correct header data on a CORS request, so your browser assumes it has no rights to access the data, and refuses to GET or POST to the URL.

    If you truly want to let any website in the world run that AJAX request, you can do something similar to the following:

    function handleOptions(request, response) {
        response.writeHead(200, {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Method": "POST, GET, OPTIONS",
            "Access-Control-Allow-Headers": request.headers["access-control-request-headers"]
        });
        response.end();
    }
    
    function server(request, response) {
        if(request.method == "POST") {
            handlePost(request, response);
        } else if(request.method == "OPTIONS") {
            handleOptions(request, response);
        } else {
            handleOther(response);
        }
    }
    https.createServer(sslObj, server).listen(9001);
    

    You can fill in the details and whether you should handle GET separately, and so on (handleOther should return an appropriate error code for each request method you don’t support).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following node.js server running on 172.16.1.218: var net=require('net'); var server =
i have the following code: var net = require('net'); var server = net.createServer(function (stream)
I have the following in my node server using Express (truncated to the important
I have the following HTML node structure: <div id=foo> <div id=bar></div> <div id=baz> <div
I need to have following attribute value in my XML node: CommandLine=copy $(TargetPath) ..\..\&#x0D;&#x0A;echo
I have the following input: <node TEXT=txt> <node TEXT=txt> <node TEXT=txt/> <node TEXT=txt/> </node>
I have the following XPATH line: //det[@nItem=1]/prod/cProd That successfully selects the desired node using
I have atleast 16 functions of the following form. bool Node::some_walker( Arg* arg1 )
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have set up WebDAv server on my Debian linux and this is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.