title: Getting the Bad request error 400 trying to send XMLHttpRequest to http://api.lbs.yandex.net/geolocation
body: <p>I need to send XMLHttpRequest to the Yandex server</p>
  
  <p>I get the Bad Request error (400) and:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load <a href="http://api.lbs.yandex.net/geolocation" rel="nofollow noreferrer">http://api.lbs.yandex.net/geolocation</a>. No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>' is therefore not allowed access.
    The response had HTTP status code 400.</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>var xhr = new XMLHttpRequest();
  var url = "http://api.lbs.yandex.net/geolocation";
  
  xhr.open("POST", url, true);
  xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  
  xhr.onreadystatechange = function () {
    &lt;some code&gt;
  };
  
  var data = JSON.stringify({
   "common": {
     "version": "1.0",
     "api_key": &lt;here goes API key&gt;
     },
     "gsm_cells": [
     {
     "countrycode": params[0],
     "operatorid": params[1],
     "cellid": params[3],
     "lac": params[2],
     "age": 0
     }
     ]
  });
  
  xhr.send(data);
  </code></pre>
  
  <p>I can't find the solution for such a simple(?) thing!</p>