You forgot to initiate an instance of XMLHttpRequest
:
var http = new XMLHttpRequest();
You need to use encodeURIComponent
to properly encode your query parameter:
http.open('get', 'http://surfkid.redio.de/linki.php?site_url='+encodeURIComponent(link));
You want to attach an event listener to http.onreadystatechange
, but you're actually calling insertReply
and set its return value instead. Get rid of those parentheses:
http.onreadystatechange = insertReply;
UPDATE: chrome.tabs.getSelected
works asynchronously, so when accessing link
after the function is executed, it probably still is undefined
(also see How can I get the URL for a Google Chrome tab?) Put your code in the callback handler. Complete script:
var wid,
http = new XMLHttpRequest();
chrome.tabs.getSelected(null,function(tab) {
http.open('get', 'http://surfkid.redio.de/linki.php?site_url=' + encodeURIComponent(tab.url));
http.onreadystatechange = insertReply;
http.send(null);
});
function insertReply() {
}