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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:21:14+00:00 2026-06-08T21:21:14+00:00

In my index.js, I have an exports function that is supposed to send data

  • 0

In my index.js, I have an exports function that is supposed to send data back to the client via ajax on pressing a submit button. However, when the user presses submit, the data seems to get sent over before it the data gets modified. When pressing submit one more time, it sends the data that was previously modified as if clicking the submit button only sends the ‘previously’ set data. This is my code:

        var tabledata = getRecordFromDatabase(key);
        if(tabledata.length === 0)
            tabledata = 'There is no matched record in the database';
        res.contentType('text/html');
        res.send({'matched':tabledata});

So to illustrate the error: I click submit after filling out a form and receive back the message “There is no matched record in the database”. I hit submit a second time without changing anything in the form I just filled. This time record data is actually sent to me. Why could this be?

  • 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-08T21:21:15+00:00Added an answer on June 8, 2026 at 9:21 pm

    If whatever you’re doing in getRecordFromDatabase is asynchronous and non-blocking, then node.js is behaving as it should. Node.js is non-blocking – it doesn’t stop and wait for processes to complete (unless those processes are intentionally written to block, which is usually avoided in node.js). This is beneficial, because it keeps the server free to accept new requests and process many requests at once.

    If your database call is asynchronous, you’re not waiting for it to return before you res.send(). That’s why your first submit returns back empty. Most likely, by the time you hit submit a second time, your DB call has finally returned, and that’s why you get a result.

    It’s hard to give you a code-based answer to your problem, because you abstracted away what is happening in your DB call method. But typically, an asynchronous call would go something like:

    getRecordFromDatabase(key, function(err, data){
        if(data.length === 0)
            data = 'There is no matched record in the database';
        res.contentType('text/html');
        res.send({'matched':data});
    });
    

    This way, you are passing a function to execute as a callback to your asynchronous method – when the async call completes, it executes the callback, which then executes the res.send() with the appropriate data.

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

Sidebar

Related Questions

What I have: A swf exports a function via ExternalInterface Javascript creates new embed
Say i have this code to separate routes in expressjs: module.exports = function(express,app,client) {
I have an SSIS package that exports data from a table on a SQL
I have node module that exports REST methods for express.js (index, show, update, delete)..
How do I find documents in my index that have a SCHEMA-INDEX-MISMATCH? I have
I have a index.php page that is the main page. All pages are included
For example I have: (function (exports, $, _, CategoriesController) { use strict var App
I have a component in joomla that exports to PDF, the problem that i'm
I have the HTML: <div> <span class=label><a href=/index/1>Bookmix Offline</a></span> <span class=button><a href=/settings/>Settings</a></span> <span class=button><a
Scenario I have an export.php file that remotely exports a 1000 images. It's broken

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.