BLUF: Running AJAX call from Chrome extension isn’t working properly.
AJAX:
$.ajax({
type: "GET",
url: "http://weather.aero/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=KFBG&hoursBeforeNow=1&fields=raw_text",
dataType: "xml",
success: function(xml){
$(xml).find("raw_text").each(function(){
var metar = $(this).text();
});
$("#ob-body").html(metar);
}
});
So I’m trying to get weather data from a site that requires a GET to request the data XML. They give tips for building the request string for the URL, and upon pasting the URL in the address bar, the appropriate XML data displays correctly.
Next, I assembled the AJAX call and ran it, but nothing seems to happen. I changed the function for the success property to simply ‘alert()’ and ran the extension again, and the alert box popped up.
The fact that the alert is showing up means that the call was successful, unless i’m totally out to lunch … so why isn’t the original function working? I realize that the code searching the XML might not be right, but placing an alert right before I start dealing with the doc isn’t popping up either, which tells me for some reason it’s not entering the function at all.
It may because of the Same Origin Policy constraints of the AJAX requests. Chrome allows you to make cross domain ajax request in the extensions but we need to add permissions to the extension manifest file as given in the document
Looks like you may have to add cross domain access permission to the manifest file like