Js uses post to upload data to the server, and responseText returns an error

my index.js code goes like this:
aims to upload a random number string to the server, and then console.log the server"s return value.

var randomNum =  Math.floor(Math.random() * 5).toString();
        console.log(randomNum);
        var xhr = new XMLHttpRequest();  //XHR
        xhr.open("post","helloWorld.js");
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4) {
                if((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
                    console.log("ok:"+xhr.status);
                    console.log(xhr.responseText);
                }else {
                    alert("Request was unsuccessful:" + xhr.status);
                }
            } //if
        };
        xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
        xhr.send(randomNum); 

then my node.js code running on the server, called helloWorld.js, goes like this:
aims to receive random numbers from the browser and then return "ok"

//
var http = require("http");
var url = require("url");
var querystring = require("querystring");
console.log("!!!");
//
var server = http.createServer( function(request, response) {
        console.log("?????");
        console.log(request);
        var getData = "";
        request.on("data", function(chunk){ getData += chunk;});
        console.log(getData);
        //response.writeHeader(200,{"Content-Type":"text/javascript;charset=UTF-8"});
        response.write("ok");
        response.end();
});

//
server.listen(3333,function(){
        console.log("Server running...");
});

when I open the website: the console output of
1.chorme is as follows:
the first line is the random number I generated
the second line is console.log ("ok:" + xhr.status); the third line of the output
is console.log (xhr.responseText); the problem lies here, instead of returning "ok", it shows the code of the file helloWorld.js on the server, which is why? How to display the correct result "ok"?

clipboard.png

2.:
""

clipboard.png

ask for advice! Thank you very much!

Mar.09,2021

are you sure the environment is not working properly, using a random number of js html, running by another virtual service, such as live-server or http-server ? The
node section also does not see you write the page service, so it is certainly not the html that runs with the node you wrote. At the same time, you didn't write the port number for the request for helloWorld.js , so you must go directly to the interface of the virtual service (and then the virtual service goes directly to the static file service it provides), not the node you wrote.

< hr >

the error in the comment is caused by cross-domain, so it is changed to

.
response.writeHeader(200, {
 "Content-Type":"text/javascript;charset=UTF-8",
 // 
 "Access-Control-Allow-Origin": "*"
 // 
});

xhr.open("post","http://127.0.0.1:3333");

Cross-domain processing:
helloWorld.js

var server = http.createServer( function(request, response) {
    response.setHeader('Access-Control-Allow-Origin', '*');
    response.setHeader('Access-Control-Allow-Methods', '*');
    ...
Menu