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

  • Home
  • SEARCH
  • 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 8349549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:02:12+00:00 2026-06-09T08:02:12+00:00

I’m trying to do a simple conection (request – response) from the javascript code

  • 0

I’m trying to do a simple conection (request – response) from the javascript code on a web to a server in Node.js.

I have tried to make the request as follows:

var request = new XMLHttpRequest();
request.open('GET', 'http://localhost:4444/', false);
request.send(); 

if (request.status === 200) {
  console.log(request.responseText);
}

Running this code I got an error in FireBug

I have continued searching and I found that this method is only to make GET requests on the same domain. To make cross domain requests we must use other strategies.

I found a jQuery method, and it seems that i’m on the right way:

$.get(
    'http://localhost:4444/',
    function(data) {
        alert("sucess"); 
        //Do anything with "data"
    }
);

In this case I get the same response without the error.

It seems it works but the "alert" message is never shown! What happens? What am I doing wrong?

The Node.js server code is:

var http = require("http");

http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("Response");
    response.end();
}).listen(4444);
  • 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-06-09T08:02:14+00:00Added an answer on June 9, 2026 at 8:02 am

    So you’re running into cross domain issues. You have a few options:

    1) since you’re using node, use socket.io . It’s cross domain compliant.

    On the client:

    <script src="Full path to were socket IO is held on your server//socket.io.js"></script>
    <script>
        var socket = io.connect();
    
        socket.on('some_callback', function(data){
            // receive data
        });
    
        socket.emit('some_other_callback', {'data': value}); //send data
    </script>
    

    Server:

    var io = require('socket.io').listen(server);
    
    // define interactions with client
    io.sockets.on('connection', function(socket){
        //send data to client
        socket.emit('some_callback', {'data': value});
    
        //recieve client data
        socket.on('some_other_callback', function(data){
            //do something
        }); 
    });
    

    2) Since you just want to use GET you can use JSONP

    $.getJSON('url_to_your_domain.com/?callback=?&other_data=something,
        function(data){
            //do something
        }
    );
    

    Here we pass your normal GET params as well as callback=?. You will return the following from your server:

    require('url');
    var r = url.parse(req.url,true);
    r.query.callback + '(' + some JSON + ')'
    

    3) If you don’t care about all browser compatibility you can use CORS:
    You can see a much better example than I would be able to write Here

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.