0

I would like to call a jsonp callback from a typescript module of devextreme. The following code is not working. I would like to call weatherResponse callback, but it's inside the TypeScript module.

module tellmeweather {
    export function home(params: { id: any }) { 
        return {
            LocationValue: ko.observable("New York"),
            LocationResults:ko.observable("No Results"),
            goSearch: function () 
            {

                $.ajax({
                    url: 'http://api.openweathermap.org/data/2.5/weather?q='
                         + this.LocationValue() + ',it&callback=weatherResponse',
                    dataType: 'jsonp',
                    jsonp: 'weatherResponse',
                    success: function () {

                    }
                });
            }
            ,
            weatherResponse: function (locdata:any)
            {    
                this.LocationResults("Location Name:"+locdata.name);    
           }
        };
    }
}
Markus
  • 3,225
  • 6
  • 35
  • 47

1 Answers1

0

Don't specify 'jsonp' parameter at all. Let jquery work it out. Do ajax request like the following

$.ajax({
    url: 'http://api.openweathermap.org/data/2.5/weather?q=' + this.LocationValue() + ',it&callback=?',
    dataType: 'jsonp'
}).done(function(result) {
    // code here
});

You can find working script on github https://github.com/nils-werner/owm-display/blob/master/js/loader.js

tabalin
  • 2,303
  • 1
  • 15
  • 27