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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:03:26+00:00 2026-06-15T09:03:26+00:00

I am migrating my work from an old environment to a newer one. Im

  • 0

I am migrating my work from an old environment to a newer one. Im in the middle of updating outdated code with newer one and it seems to be running well(my web service written in node.js)

I have my webservice running in node.js and my site using jquery.
node.js code

var express = require('express');
var app = express();

app.get('/', function(req, res){
    console.log('GET request to /');
});

app.listen(8888);
console.log('Express server started on port 8888');

Here is my jquery code

$.getJSON('http://URL:8888/getTables', function(data){
    //stuff
});

however in firebug the console shows:

"http://URL.com:8888/getTables 200 OK 64ms"

with no response

if i go to the site directly
“http://URL.com:8888/getTables”
i get my data.

any ideas what is going on? i’ll leave the web service running so you can see what im talking about.

the site that is using it is http://www.URL.com/db/index.html

edit:

  app.get('/getTables', function(req, res){
     console.log('GET request to /getTables');
     getTables(req, res);
     sendJSON(res, 200, cache_tables);
  });

function sendJSON(res, httpCode, body)
{
  var response = JSON.stringify(body);
  res.send(response, {'Access-Control-Allow-Origin': '*'}, httpCode);
}

UPDATE

I found my solution, thanks for letting me know my issue was cross-domain, i thought my sendJSON took care of it but since i upgrading nodejs and the modules it probably become obsolete. Here is the fix for those wondering:

//Middleware: Allows cross-domain requests (CORS)
var allowCrossDomain = function(req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  next();
}

//App config
app.configure(function() {
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({ secret: 'secret' }));
  app.use(express.methodOverride());
  app.use(allowCrossDomain);
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

and i had to update all of my gets to use:

 app.get('/', function(req, res, next){
   console.log('GET request to /');
 });
  • 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-15T09:03:30+00:00Added an answer on June 15, 2026 at 9:03 am

    It’s because you’re running the server on another port so it’s considered x-domain. You could set it up to use JSONP

    This SO question goes into more detail How do I send an AJAX request on a different port with jQuery?

    Here is another post going into details about CORs http://www.bennadel.com/blog/2327-Cross-Origin-Resource-Sharing-CORS-AJAX-Requests-Between-jQuery-And-Node-js.htm

    [update for comment below]

    I found a post that has an example setup for using express to serve out jsonp, hopefully this will help…

    http://kiwidev.wordpress.com/2011/07/18/node-js-expressjs-and-jsonp-example/

    code examples from that post are below:

    express app

    var express = require('express');
    
    var app = module.exports = express.createServer();
    
    app.configure(function(){
        app.set('views', __dirname + '/views');
        app.set('view engine', 'jade');
        app.use(express.bodyParser());
        app.use(express.methodOverride());
        app.use(app.router);
        app.use(express.static(__dirname + '/public'));
    });
    
    app.get('/logget', function(req, res){
        console.log('get to log');
        console.log(req.query.callback);
        console.log(req.param('somedata'))
    
        res.header('Content-Type', 'application/json');
        res.header('Charset', 'utf-8')  
        res.send(req.query.callback + '({"something": "rather", "more": "pork", "tua": "tara"});');  
    });
    
    app.listen(3000);
    console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
    

    HTML page that access it

    <html>
        <head>
            <title>jsonp test</title>
            <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>      
            <script type="text/javascript">
                $(function(){               
                    $('#jsonThingLink').click(function(e){
                        e.preventDefault();
                        console.log('jsonThingLink clicked');                   
    
                         $.ajax({
                            dataType: 'jsonp',
                            data: "somedata=blahblah",                      
                            jsonp: 'callback',
                            url: 'http://localhost:3000/logget?callback=?',                     
                            success: function(data) {
                                console.log('success');
                                console.log(data);
                                console.log(data.more);                
                            }
                        });
                    });             
                });
            </script>
        </head>
        <body>
            <div id="jsonThing"><a href="#" id="jsonThingLink">test jsonp</a></div>    
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are migrating our web sites from Win2003/IIS6 to Win2008/IIS7. Our .NET code is
I work on some project that is migrating from vb6 to web (asp.net). I
I am migrating from a Dreamweaver forced working environment to a free-of-choice one. That
I'm migrating a legacy codebase at work from python 2.4 to python 2.6. This
Migrating a legacy application from WebSphere v.6 to WebSphere v.8. The application's web.xml only
I am attempting to migrate hosts and am having issues migrating from one Drupal
I'm migrating an e-commerce app from an old php framework to ASP.NET MVC. Some
I'm migrating some stuff from one mysql server to a sql server but i
i'm with a problem migrating an old application from MyFaces 1.1 to MyFaces 1.2.
We're migrating from Bugzilla to Redmine and there's one feature of bugzilla which I'm

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.