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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:48:39+00:00 2026-06-04T07:48:39+00:00

I am building a small prototype, and have the following problem: I am trying

  • 0

I am building a small prototype, and have the following problem:

I am trying to communicate between client-side jQuery, and server-side node.js; when I make a jQuery ajax request to my node.js code, it just gives me the code, not the output of the code.

What am I doing wrong?

Part of client.js:

$.ajax({url      : './../includes/get_data.js', 
        success  : function(data) {
          alert('success!');
        },
        error    : function(data) {
          alert('error!');
        }
});  

get_data.js:

var fs = require('fs');

console.log('test');

When I make a request to get_data.js, the output I want is:
test

But instead I get the source code:

var fs = require('fs');

console.log('test');

Many thanks

  • 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-04T07:48:40+00:00Added an answer on June 4, 2026 at 7:48 am

    You’re just asking for a static .js file, you’re not interacting with Node at all. If you want to do so, make an HTTP server (copy the example on http://nodejs.org/), bind it to a port and write a response back, don’t use console.log (which will only output to the console).

    Example:

    Save the following file as app.js and then run it in the terminal with node app.js then visit localhost on port 1337:

    var http = require('http'),
        ajaxResponse = { 'hello': 'world' },
        htmlContent;
    
    htmlContent  = "<html><title></title><head>";
    htmlContent += "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>";
    htmlContent += "<script>$(function() {$.ajax({url:'/ajax',success:function(data){alert('success!');console.log(data);},error:function(data){alert('error!');}});});</script>";
    htmlContent += "</head><body><h1>Hey there</h1>";
    htmlContent +="</body></html>";
    
    http.createServer(function (req, res) {   
      if (req.url === '/ajax') {
        res.writeHead(200, {'Content-Type': 'text/json'});
        res.end(JSON.stringify(ajaxResponse));
      } else {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(htmlContent);  
      }  
    }).listen(1337, '127.0.0.1');
    console.log('Server running at http://127.0.0.1:1337/');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a small game - rock paper scissors. I have a prototype -
I am building a small dropdown menu with jQuery, but i am have a
Im building a small webshop and have run into a problem. The company which
I am building a small facebook app. Trying to search for values in an
I'm building a small CMS in PHP for a client and something I've noticed
I'm building a few small prototypes in Silverlight and have quite a bit of
i'm currently building a small music quiz running node.js 0.4.12 and the express framework
I am building a small webapp for my website and have included tinyMCE as
I am building a small app which captures mouse clicks. I wrote the prototype
Im building a small space shooter game. I have how ever stubbed on a

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.