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 8799567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:21:31+00:00 2026-06-14T00:21:31+00:00

I am new to node.js and I am trying sending data from AJAX to

  • 0

I am new to node.js and I am trying sending data from AJAX to Node.js server and getting back the things.My server side code is

var http = require('http');
var url=require('url');
http.createServer(function (req, res) {
    console.log(req.url);
     var url_parts = url.parse(req.url, true);
    switch(url_parts.pathname)
    {
        case '/':
        res.writeHead(302,{'location':'http://localhost/testajax/index.html'});
        res.end();
        break;
        case '/test':
    console.log('request received');
    res.writeHead(200, {'Content-Type': 'text/html'});
    console.log(url_parts.query["page"]);
    res.end(url_parts.query["page"]);
    break;
}
}).listen(8124);

And that running on client side is

   <script type="text/javascript">

   $(document).ready(function() {
    $('a').click(function(){

            $.get('http://localhost:8124/test', {'page':$(this).text()}, function(data){
            alert(data);
                $('#content').html(data);

            });                       

        });

    });

    </script>

The content is in the <div> but that doesnt show up neither does it alert anything.On consoling the browser I get this error.

XMLHttpRequest cannot load http://localhost:8124/test?page=ProfilePage. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

Is this a wrong way of doing things?Please help.

  • 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-14T00:21:33+00:00Added an answer on June 14, 2026 at 12:21 am

    It seems that you are trying to make a request outside your domain. Have a look at this answer: https://stackoverflow.com/a/9327231/1417431

    You could have a further read here: Same origin policy

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

Sidebar

Related Questions

I'm trying to call a server-side action in a controller from jQuery: $.ajax({ url:'http://localhost:88/admin/business/11/GetChildBusinessTypes',
I am trying to create a new node type like this: http://www.live-wtr.ru/leo/Tikz9.png but don't
I have below updateFile code, here I am trying to add new node when
I am trying to create a server-side solution which periodically pushes data to the
I'm new into Node.js and trying to learn. From what I have understood it's
New to Node.js and Express, I am trying to understand the two seems overlapping
I'm trying to add a new nova-compute node (KUubuntu 12.04) to my single node
I am new to hadoop and trying to get a single node setup of
I'm pretty new to Node.js/Express, but I think I'm slowly getting the hang of
I'm quite new to node and am trying to create something that gets some

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.