0

I have a form where i post data to a webagent which is on another domain(the form is on localhost and the post is to a http://thisisnotareallink.com)

If i use:

<form id="msform" action="http://thisisnotareallink.com"method="post">

then it works and i get data like bla=2&dsaf=2

but if i use:

 <form id="msform"  method="post">

and then in script have something like:

var xhr = new XMLHttpRequest();
  xhr.open(form.method, 'http://thisisnotareallink.com', true);
  xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');


  // send the collected data as JSON
  xhr.send(JSON.stringify($('#msform').serializeObject()));

or

 $.ajax({
  url: "http://thisisnotareallink.com",
  type: "POST",
  dataType: "json", // expected format for response
  contentType: "application/json", // send as JSON
  data: JSON.stringify($('#msform').serializeObject()),

then if i check the chrome inspector > Network > XHR then i get:

No 'Access-Control-Allow-Origin' header is present on the requested resource

why is this so ?

Jai
  • 74,255
  • 12
  • 74
  • 103
Nuri Ensing
  • 1,899
  • 1
  • 19
  • 42
  • This line says everything : **No 'Access-Control-Allow-Origin' header is present on the requested resource**. – Jai Aug 24 '15 at 10:41
  • Maybe `http://thisisnotareallink.com` accepts only Content-Type: __multipart/form-data__ or __application/x-www-form-urlencoded__ instead of __ajax__? – Medet Tleukabiluly Aug 24 '15 at 10:42
  • Because this header is not present you can't share data with that origin. – Jai Aug 24 '15 at 10:43

0 Answers0