Skip to content Skip to sidebar Skip to footer

Make Post Json Request From Html Script To A Node.js App In Another Domain

I am trying to send string data via making a post json request by javascript inside an .erb.html file, to a node.js app in another domain, which uses express to handle incoming req

Solution 1:

To do it with an XMLHttpRequest, the remote server would have to have CORS heaers configured.

From MDN:

A resource makes a cross-origin HTTP request when it requests a resource from a different domain, protocol, or port to its own. For example, an HTML page served from http://domain-a.com makes an src request for http://domain-b.com/image.jpg. Many pages on the web today load resources like CSS stylesheets, images, and scripts from separate domains.

For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. For example, XMLHttpRequest and Fetch follow the same-origin policy. So, a web application using XMLHttpRequest or Fetch could only make HTTP requests to its own domain. To improve web applications, developers asked browser vendors to allow cross-domain requests.

Post a Comment for "Make Post Json Request From Html Script To A Node.js App In Another Domain"