HTML5 WebWorker Library Sample

Hacking around for fun and profit

by shelbyz

HTML

<body>
    <button id="post">Post</button>
    <br/>
    <button id="get">Get</button>
    <br/>
    <label id="final">Results: </label>
</body>

JavaScript

//debugger;

function postCallback() {
    alert("I'm the post callback");
}

function getCallback() {
    alert("I'm the get callback");
}

var worker = new Worker("http://dl.dropbox.com/u/75275447/worker.js");

worker.onmessage = function(e) {
    if(e.data.verb === 'post') {
        postCallback();
    }
    else {
        getCallback();
    }
};

$("#post").click(function() {
    var data = {
        verb: "post",
        url: "http://www.sample.com/",
        data: "This is some data",
        successFunc: postCallback,
        contentType: "application/json"
    };
    
    this.worker.postMessage(data);
    
    //document.getElementById("frame1").contentWindow.postMessage(JSON.stringify(data), "http://dl.dropbox.com");
});

$("#get").click(function() {
    var data = {
        verb: "get",
        targetPath: "/samples",
        successFunc: getCallback,
        acceptType: "application/json"
    };
    
    this.worker.postMessage(data);
    
    //document.getElementById("frame1").contentWindow.postMessage(JSON.stringify(data), "http://dl.dropbox.com");
});