title: XMLHttpRequest cross domain
body: <p>i have this javascript code for extract text from page, it works fine if i open file in my domain, but i cant get text from file in another domain, because some security reasons. So my question is how can i please extract text from another website in javascript, please without jquery.</p>
  
  <p>Thank you</p>
  
  <pre><code>function reqListener () {
    console.log(this.responseText);
  }
  
  var xhr = new XMLHttpRequest();
  
  xhr.onload = reqListener;
  
  xhr.onreadystatechange = function() {
      if (xhr.readyState == 4) {
          alert(xhr.responseText);
      }
  }
  xhr.open('GET', 'http://anotherweb.com/datafile.php', true);
  xhr.setRequestHeader('Content-Type', 'text/plain');
  xhr.send(null);
  </code></pre>
  
  <p>I tried this and it doesnt work.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;script&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;
  
  $(document).ready(function(){
    $("button").click(function(){
      $.ajax({
        url: "http://localhost/index.php",
        dataType : "json",
        contentType: "application/json; charset=utf-8",
        cache: false,
        success: function(response) {
          alert(response);
        },
        error: function (e) {                
        }
        });
    });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;button&gt;Send an HTTP GET request to a page and get the result back&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>