how do I return data from a node.js request call? (undefined is not a function)

how do I return data from a node.js request call? (undefined is not a function)

Content Index :

how do I return data from a node.js request call? (undefined is not a function)
Tag : node.js , By : Shawazi
Date : November 24 2020, 03:41 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

I receive correct data from JSON request but when I want to return the result from the function I get "undefined&qu

Tag : php , By : user140973
Date : March 29 2020, 07:55 AM
Any of those help The problem is that getJSON is asynchronous.
console.log(operations) is executing before the JSON request has actually been completed. You can see this in the console.log where the undefined line will appear above the options.
$.getJSON(window.location.pathname+'/ajaxRequest?ordernumber='+Ordernumber+'&'+Math.round(new Date().getTime()), function(data) {
    if(data['articleID']) {
        options = data['values_label_array'];   
        console.log(options)    // returns {"1":"Option 1","2":"Option 2"}
        processJSON(options );

function selectOptions(){

function processJSON(data) {
   //do something with the JSON;

When i call the ajax in node.js as a return undefined

Tag : javascript , By : helloedwin
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You said typeof (result) is string, hopefully JSON. But if want to iterate over it, then you have to parse as javascript array
var resultArray = JSON.parse(result);
$.each(resultArray, function(index, item) {

About node.js return data to ajax call function

Tag : javascript , By : ChrisMe
Date : March 29 2020, 07:55 AM
wish helps you On your server code. The one with http.createServer(function (req, res) {...}
Notice how you got a req and res parameter?

Node.js request.post return undefined

Tag : javascript , By : Nosayaba
Date : March 29 2020, 07:55 AM
it helps some times You can't use return inside a callback to return a value when your function is called. You could pass mysqlVerify a callback (a function which is run once the result is determined) and call it once you get a response, like so:
mysqlVerify = (socialclub_id, session_id, callback) => {
        url: 'http://myapi.site/VerifyUser',
        method: 'post',
        form: {
            socialclub_id: socialclub_id,
            session_id: session_id
    }, (error, response, body) => {
        if(error) {
            callback(false)       // call the function if false
        } else {
            console.log(response.statusCode, body)
            callback(body == "1") // call the function if condition met

Node.js request function return data

Tag : node.js , By : user116330
Date : March 29 2020, 07:55 AM
Hope that helps
What if I want getNumResults() to return responseJSON.results.count? How could I do this?
// load a version of the request library that returns promise instead of
// taking plain callbacks
const rp = require('request-promise');

function getNumResults(url) {
    // returns a promise
    return rp(url).then(body => {
        // make the count be the resolved value of the promise
        let responseJSON = JSON.parse(body);
        return responseJSON.results.count;
getNumResults(someURL).then(count => {
    // use the count result in here
    console.log(`Got count = ${count}`);
}).catch(err => {
    console.log('Got error from getNumResults ', err);
Related Posts Related QUESTIONS :
  • Adding title element to paperjs SVG (using node.js)
  • Wait for firestore queries to finish before return a cloud function response
  • How to upload files larger than 10mb via google cloud http functions. ? Any alternative options?
  • How to use the NODE_OPTIONS environment variable to set the max_old_space_size globally in Windows?
  • Is nodejs representing Reactor or Proactor design pattern?
  • How to reference generated Prisma schema in my schema.graphql file for a query that filters by id
  • Cant figure out what is wrong with my models
  • npm ERR! EPROTO: protocol error, symlink '../@babel/parser/bin/babel-parser.js' -> '/home/vagrant/code/proadco.test/n
  • express-session - the difference between session id and connect.sid?
  • How do you run this list of command that come from a book Eloquent Javascript Node.js
  • how to convert from import to require in nodejs
  • POST request returns undefined
  • How to read large json file in node js?
  • AWS Lambda function written in nodejs is not updating my DynamoDB
  • Best way to define a Map Object in GraphQL Schema?
  • bigchaindb-driver not found in node_modules?
  • Upgrading yarn in root directory do not upgrade Workspace dependencies
  • How can I redirect all clients to another page with socket.io?
  • How is `cluster` and `worker_threads` work in Node.js?
  • AWS Lambda - Not able to a access JS file bundled in Layer (Node.js)
  • How to connect AWS Bitnami Certified Kafka AMI with Elastic Beanstalk nodejs environment using kafka-node
  • Define Shortcut Keys by user (add or edit by user in web app)?
  • 'this' in regular function vs fat arrow function in ES6, illustrated with an example of Mongoose
  • Could not find the implementation for builder @angular-devkit/build-angular:dev-server on ng serve command
  • The engine "node" is incompatible with this module
  • fs.readDirSync can't find dir in typescript?
  • Difference between keepAliveTimeout and timeout?
  • Visual Studio Code: "'tslib' cannot be found" error in Angular project
  • Embedding twitter timeline does not render in angular 7
  • Secret environment variables in Cloudbuild (with out files), how?
  • more than one 2dsphere index, not sure which to run geoNear
  • Why only 50 instances working on AWS lambda?
  • VSCode debugging (F5) react app gives SyntaxError: Unexpected identifier
  • How to use sweetalert in nodejs?
  • ng update --all does say 'Repository is not clean' evendought git commit
  • I want to update user profile
  • Uncaught ReferenceError: __webpack_dev_server_client__ is not defined
  • Webpack not being recognized after updates
  • use firebase Storage with Admin sdk node.js
  • If I want my graphql endpoint to be something other than `/graphql`, how do I configure it with the `GraphqlModule`?
  • Node.js JWT token
  • Filtering the user data with the age max and age min while date of birth is present in schema
  • What is the right way of implementing a service in an Angular application?
  • Redis doesn't update when many requests at once
  • Passport + SAML with metadata.xml file
  • downgrade NPM version on mac
  • tar EPERM: operation not permitted, futime
  • Two Public subnets can not communicate with private ip
  • How to upload file to Group Drive (Shared Drive) with Google Drive API V3?
  • Why is Firestore returning inconsistent results when queried inside Cloud Functions?
  • How to make post request with data in test-cafe?
  • React app not working in Internet Explorer 11
  • Node.js how to use socket.io in express route
  • What incorrect Metadata-Flavor header at GoogleAuth means?
  • Insert if not exists, if exists update
  • SyntaxError: await is only valid in async function with argon2
  • storing PDF files in mongoose using Node.js and Angular 6
  • How to use localStorage Carefully in Angular
  • How does one create a Stripe order with invoice?
  • What is GET/ error in node.js application?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com