Skip to content

Instantly share code, notes, and snippets.

@xxx
Created August 9, 2009 19:03
Show Gist options
  • Save xxx/164876 to your computer and use it in GitHub Desktop.
Save xxx/164876 to your computer and use it in GitHub Desktop.
****** index.html
<html>
<head>
<title></title>
</head>
<body>
<script>
var dude = new Worker('my_worker.js');
dude.onmessage = function(e) {
alert(e.data);
};
dude.postMessage('go for it');
</script>
</body>
</html>
****** my_worker.js
makeRequest = function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://www.google.com/');
req.onreadystatechange = function (e) {
if (req.readyState == 4) {
if(req.status == 200)
postMessage(req.responseText);
else
postMessage("we have gremlins");
}
};
req.send(null);
}
onmessage = function(e) {
makeRequest();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment