I am attempting to create a chrome extension that queries an external source as a reference to block or allow through a particular page. The following is part of my code. I am new to javascript, and scope always seems to be something that screws me up.
chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
        var http = new XMLHttpRequest();
        var url = "http://xxx.xx.xxxx";
        var params = "urlCheck="+encodeString_(details.url);
        http.open("POST", url, true);
        //Send the proper header information along with the request
        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                guilt = 0;
                console.log(guilt);
            }else if(http.readyState == 4 && http.status == 404){
                guilt = 1;
                console.log(guilt);
            }
        }
        http.send(params);
    if(guilt == 1){
        return {cancel: true};
        }else{
        return {cancel: false};
        }
    },
    {urls: ["<all_urls>"],
     types:["main_frame"]
    },
    ["blocking"]
    );
Any help would be greatly appreciated! Thanks.
 
     
    