Ok, I solved the problem. The problem was that you cannot make XMLHttp request to some other domain while residing on some other due to same origin policy .
Therefore when contentScript made XMLHttp request to the server, the browser throws NS_error_failure
.
The solution I found is to use Request API of Addon SDK . The Request object is used to make GET, POST, or PUT network requests. The Request object is not subjected to same-origin-policy.
So instead of making Http request from contentScript, I used request API and got the valid response.
The modified code main.js :
var widgets = require("sdk/widget");
var tabs = require("sdk/tabs");
var data = require("sdk/self").data;
var Request = require("sdk/request").Request;
var url;
var domain_name;
var requestURL;
var showipWidget = widgets.Widget({
id : "show-ip",
label : "Display IP Address of current Page",
contentURL : data.url("lens_icon.png"),
contentScriptFile : [data.url("click_handler.js"),data.url("jquery-1.8.3.min.js")],
panel : infoPanel,
onClick : function() {
var curtab = tabs.activeTab;
url = curtab.url;
this.port.emit('getDomain',url);
}
});
showipWidget.port.on("setDomain", function(domain) {
domain_name=domain;
getDomainInfo(domain_name);
});
function getDomainInfo(domain) {
requestURL = "http://dazzlepod.com/ip/"+domain+".json";
//requestDomainInfo.get();
Request({
url: requestURL,
onComplete: function (response) {
var out = response.json;
console.log("Response: "+out.ip);
}
}).get();
}
And the Content Script click_handler.js
function getDomain(url) {
var a = document.createElement('a');
a.href = url;
var domain = a.hostname;
return domain;
}
var check = self.port.on("getDomain", function(url) {
var domain = getDomain(url);
self.port.emit("setDomain",domain);
});
All files are on GitHub.
Thank You Everyone for your help.