Get data from third party Node.js server hosted on Vagrant VM using jQuery - JSONP

milky_jay

I've got a Node.js server listening on localhost:3000 working as a black box that outputs UI that I want to load into a local website.

The consuming service written in jQuery is:

$('.my_selector').click(function(){
    $.ajax({
        url: ':3000/',
        method: "POST",
        success: function(data) {
            $("#content").append(data);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert('error ' + textStatus + " " + errorThrown);
        }
    });
});

Instead of visiting the page directly it loads content and appends it to #content.

The issue is that the code does not work.


Edit:

If I set localhost:3000 to url I get XMLHttpRequest Exception:

jquery.min.js:4 XMLHttpRequest cannot load localhost:3000/. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource
morels

You need to use JSONP to overcome the Cross origin issue. Although both the Node server and your custom visiting webpage are on localhost, please note that there is a huge difference on configuration:

  • your custom visiting webpage is fully hosted on local LAMP stack*.
  • Node is only proxy/reverse-proxy configured locally (thanks to Vagrant automation) !

The real (virtual)IP of the Node server is the one configured on the vagrant VM, you can check it using ifconfig after opening a ssh session towards the VM. This way the HTTP response received from the page hosted locally has a different IP and domain in the header and the Cross origin exception is triggered.

*= supposing for example you are running a LAMP system.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Send REST calls from Node server to third party application using OAuth

From Dev

Send REST calls from Node server to third party application using OAuth

From Dev

Get individual values from Third Party Response Data in HTML page

From Dev

How can I send data from a Node.js application hosted on Heroku to a PHP file hosted on a completely separate (Cpanel) server?

From Dev

Using cross origin JSON from third party on client side js?

From Dev

How to make a jQuery request to a locally hosted node.js server?

From Dev

In Firebase Realtime Database, how can an unauthenticated third-party server (using the Admin SDK) read unprotected data from my database?

From Dev

Cannnot get JSONP response from WebAPI using jquery

From Dev

Accessing Node.js on a Vagrant VM

From Dev

Get current IP in JS (no third party services)

From Dev

Third party cookies using jquery cookie

From Dev

Using third party js libraries with Jint

From Dev

Using third party js libraries with Jint

From Dev

Get a simple JSONP object from a remote server php file using ajax (and jquery) embedded in javascript directly in my wordpress page

From Java

How to download a file with Node.js (without using third-party libraries)?

From Dev

get json data that have third brackets from url using jquery or javascript

From Dev

get page data from html page using node.js

From Dev

How to get binary data from server using JQuery?

From Dev

Android: How to get ID_TOKEN using GoogleAuthUtils from a third-party module?

From Dev

JavaScript/jQuery reference to a third party website works locally, not when hosted on godaddy run site (404 error)

From Dev

Send data to remote server using jsonp

From Dev

Debugging a node app hosted on a VM using Visual Studio Code

From Dev

Struggling to translate jQuery JSONP query to a Node.JS query using http.request

From Dev

How to read data using JSONP, Ajax and jquery?

From Dev

Using third party controls

From Dev

Call to node js server using jquery ajax

From Dev

Cannot ping VM hosted on Windows server from another PC machine

From Dev

Server on commercial VPN, wishing to avoid using third party assistance to connect

From Dev

Is it possible to register android device from third party java server?

Related Related

  1. 1

    Send REST calls from Node server to third party application using OAuth

  2. 2

    Send REST calls from Node server to third party application using OAuth

  3. 3

    Get individual values from Third Party Response Data in HTML page

  4. 4

    How can I send data from a Node.js application hosted on Heroku to a PHP file hosted on a completely separate (Cpanel) server?

  5. 5

    Using cross origin JSON from third party on client side js?

  6. 6

    How to make a jQuery request to a locally hosted node.js server?

  7. 7

    In Firebase Realtime Database, how can an unauthenticated third-party server (using the Admin SDK) read unprotected data from my database?

  8. 8

    Cannnot get JSONP response from WebAPI using jquery

  9. 9

    Accessing Node.js on a Vagrant VM

  10. 10

    Get current IP in JS (no third party services)

  11. 11

    Third party cookies using jquery cookie

  12. 12

    Using third party js libraries with Jint

  13. 13

    Using third party js libraries with Jint

  14. 14

    Get a simple JSONP object from a remote server php file using ajax (and jquery) embedded in javascript directly in my wordpress page

  15. 15

    How to download a file with Node.js (without using third-party libraries)?

  16. 16

    get json data that have third brackets from url using jquery or javascript

  17. 17

    get page data from html page using node.js

  18. 18

    How to get binary data from server using JQuery?

  19. 19

    Android: How to get ID_TOKEN using GoogleAuthUtils from a third-party module?

  20. 20

    JavaScript/jQuery reference to a third party website works locally, not when hosted on godaddy run site (404 error)

  21. 21

    Send data to remote server using jsonp

  22. 22

    Debugging a node app hosted on a VM using Visual Studio Code

  23. 23

    Struggling to translate jQuery JSONP query to a Node.JS query using http.request

  24. 24

    How to read data using JSONP, Ajax and jquery?

  25. 25

    Using third party controls

  26. 26

    Call to node js server using jquery ajax

  27. 27

    Cannot ping VM hosted on Windows server from another PC machine

  28. 28

    Server on commercial VPN, wishing to avoid using third party assistance to connect

  29. 29

    Is it possible to register android device from third party java server?

HotTag

Archive