JavaScript $.ajax is not a function when being called

See the documentation:

For jQuery to work in Node, a window with a document is required. Since no such window exists natively in Node, one can be mocked by tools such as jsdom. This can be useful for testing purposes.

var externalip = require('external-ip');

require("jsdom").env("", function(err, window) {
    if (err) {
        console.error(err);
        return;
    }
    var $ = require("jquery")(window);

     function getLocationFromIp() {
        $.ajax({
            url: "freegeoip.net/json/",
            type: "GET",
            data: null,
            dataType: "json",
            success: function() {
                console.log("success!")
            },
            error: function() {
                console.log("error", arguments[2])
            }
        });
    }
    var ip = getLocationFromIp();
    console.log(ip);
});

You'd probably be better off using an HTTP library designed to work with Node from the outset, such such as request.

Answer:1

I am no beginner in javascript. I am actually working on this for past 3-4 months but today I read this statement about "What is JavaScript?" JavaScript is single-threaded, non-blocking, ...

I am no beginner in javascript. I am actually working on this for past 3-4 months but today I read this statement about "What is JavaScript?" JavaScript is single-threaded, non-blocking, ...

  1. does javascript work on iphone
  2. does javascript work on mobile
  3. does javascript work on android
  4. does javascript work on all browsers
  5. does javascript work in email
  6. does javascript work on ipad
  7. does javascript work in html
  8. does javascript work offline
  9. does javascript work on notepad
  10. does javascript work on mac
  11. does javascript work in chrome
  12. does javascript work locally
  13. does javascript work in html email
  14. does javascript work in wordpress
  15. does javascript work in typescript
  16. does javascript work on safari
  17. does javascript work with php
  18. does javascript work in outlook
  19. does javascript work on apple
  20. does javascript work without internet

My Parse Javascript cloudcode is not working correctly. Basically all my objects have a corresponding "index/menindex & womenindex" number. If both genders are selected- all items show up (as ...

My Parse Javascript cloudcode is not working correctly. Basically all my objects have a corresponding "index/menindex & womenindex" number. If both genders are selected- all items show up (as ...

I have a problem when setting scope variables with two dots. See below for my controller and my error. .controller('CreateSubject', function ($scope, factory, $cookieStore, $location, $rootScope){ ...

I have a problem when setting scope variables with two dots. See below for my controller and my error. .controller('CreateSubject', function ($scope, factory, $cookieStore, $location, $rootScope){ ...

I am currently using 1.5.3 AngularJS Version & ng-include="'file.html'" is not working <!DOCTYPE html> <html lang="en-US" ng-app="myApp"> <head> <!-- Include ...

I am currently using 1.5.3 AngularJS Version & ng-include="'file.html'" is not working <!DOCTYPE html> <html lang="en-US" ng-app="myApp"> <head> <!-- Include ...