Question: How can I make requests to other server(s) (i.e. get a page from any desired server) with a JavaScript within the user's browser? There are limitations in place to prevent this for methods like XMLHttpRequest, are there ways to bypass them or other methods?

That is a general question, specifically I want to check a series of random websites and see if they contain a certain element, so I need the HTML content of a website without downloading any additional files; all that in a JavaScript file, *without any forwarding or proxy mechanism on a server*.

(Note: one way is using Greasemonkey and its GM\_xmlhttpRequest.)

Answer: 
You should check out [jQuery](http://www.jquery.com). It has a rich base of [AJAX functionality](http://docs.jquery.com/Ajax) that can give you the power to do all of this. You can load in an external page, and parse it's HTML content with intuitive [CSS-like selectors](http://docs.jquery.com/Selectors).

An example using `$.get();`

```
$.get("anotherPage.html", {}, function(results){
  alert(results); // will show the HTML from anotherPage.html
  alert($(results).find("div.scores").html()); // show "scores" div in results
});

```

For external domains I've had to author a local PHP script that will act as a middle-man. jQuery will call the local PHP script passing in another server's URL as an argument, the local PHP script will gather the data, and jQuery will read the data from the local PHP script.

```
$.get("middleman.php", {"site":"http://www.google.com"}, function(results){
  alert(results); // middleman gives Google's HTML to jQuery
});

```

Giving *middleman.php* something along the lines of

```
<?php

  // Do not use as-is, this is only an example.
  // $_GET["site"] set by jQuery as "http://www.google.com"
  print file_get_contents($_GET["site"]);

?>

```
> 
> update 2018:
> 
> 
> 

You can only access cross domain with the following 4 condition

* in response header has `Access-Control-Allow-Origin: *`

Demo

```js
$.ajax({
  url: 'https://api.myjson.com/bins/bq6eu',
  success: function(response){
    console.log(response.string);
  },
  error: function(response){
    console.log('server error');
  }
})
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
```

* use server as bridge or proxy to the target

Demo:

```js
$.ajax({
  url: 'https://cors-anywhere.herokuapp.com/http://whatismyip.akamai.com/',
  success: function(response){
    console.log('server IP: ' + response);
  },
  error: function(response){
    console.log('bridge server error');
  }
})
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
```

* using browser addon to enable `Allow-Control-Allow-Origin: *`
* disable browser web security

Chrome

```
chrome.exe --args --disable-web-security

```

Firefox

```
about:config -> security.fileuri.strict_origin_policy -> false

```

end

---

> 
> noob old answer 2011
> 
> 
> 

$.get(); can get data from *jsbin.com* but i don't know why it can't get data from another site like google.com

```
$.get('http://jsbin.com/ufotu5', {},
  function(results){  alert(results); 
});

```

demo: <http://jsfiddle.net/Xj234/>
tested with firefox, chrome and safari.