1

I have a requirement from my supervisors to make a form request in a form that resides in an external website, get the results and show them in our site. Is that even possible with Javascript ?. They have done this in Java so the requirement is based on the fact that they have done it before but my guess is that there might be security implications/restrictions on doing this.

Any help or clue would be highly appreciated Thanks in advance Luis Santos

1 Answers1

0

Completely possible. This is called a CORS request and the implementation varies dependent on the configurations of the receiving headers. IE - the external website needs to accept cross origin requests from whatever your domain is (either explicitly, or by setting a policy to allow all CORS requests - the second is pretty rare).

To get you started (you'll probably need to work out a few issues along the way) take a look at this stack overflow answer.

What is important here is the alteration of the request header via the xhr.setRequestHeader header method.

Also - your question asked specifically about javascript and so the stack overflow answer provided speaks to that. However, often times people will find the jquery.ajax() method (which is jquery's equivalent to XmlHttpRequest/XHR) a lot more straightforward and easy to use and I wanted to mention it for this reason.

Good luck!

Community
  • 1
  • 1
user239546
  • 466
  • 3
  • 7