【问题标题】:Call jsonp callback inside a TypeScript module (devextreme)在 TypeScript 模块中调用 jsonp 回调(devextreme)
【发布时间】:2014-08-18 11:42:18
【问题描述】:

我想从 devextreme 的 typescript 模块调用 jsonp 回调。 以下代码不起作用。 我想调用weatherResponse 回调,但它在 TypeScript 模块中。

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);    
           }
        };
    }
}

【问题讨论】:

    标签: jquery jsonp typescript devextreme


    【解决方案1】:

    根本不指定'jsonp'参数。让 jquery 解决它。 像下面这样做ajax请求

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

    你可以在 github 上找到工作脚本 https://github.com/nils-werner/owm-display/blob/master/js/loader.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 2012-09-12
      • 2012-06-25
      • 2020-02-22
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多