I am using AMD and Requirejs for implementing the following module:
define({
callWeatherService: function(x, y){
//var url = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD'; // website you want to scrape
var url = 'http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=' + x + '&CountryName=' + y;
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=json&callback=?';
$.getJSON(yql,displayData);
function displayData(data){
if(data.query.results){
result = data.query.results.string.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
document.getElementById("asmxResult").innerHTML = result;
// return result;
}
}
}
});
I do not want to modify the HTML document in this code but rather return the result. I have tried many different methods for callbacks from other solutions provided in stackoverflow but none seems to be working. e.g. the following code logs the result on the console but returns undefined:
define({
callWeatherService: function(x, y){
var url = 'http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=' + x + '&CountryName=' + y;
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=json&callback=?';
var result;
$(function() {
var r = GetResults();
result = r;
});
function GetResults() {
$.getJSON(yql,function(data){
if(data.query.results){
var output = data.query.results.string.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
}
console.log(output);
return output;
});
}
return result;
}
});
Is this because of using AMD and Requirejs or I am doing something wrong?