Javascript 实现$.SimpleWither AJAX请求的更好方法? 背景:

Javascript 实现$.SimpleWither AJAX请求的更好方法? 背景:,javascript,jquery,ajax,angularjs,plugins,Javascript,Jquery,Ajax,Angularjs,Plugins,我正在使用SimpleWather.js jQuery插件:与AngularJS+RequireJS一起使用 在我的一个服务文件中,我有以下AJAX请求和回调: //AJAX Request myAjaxCheck:function(city){ $.simpleWeather({ location: city, woeid: '', unit: 'c', success: function(weather) {

我正在使用SimpleWather.js jQuery插件:与AngularJS+RequireJS一起使用

在我的一个服务文件中,我有以下AJAX请求和回调:

//AJAX Request
myAjaxCheck:function(city){

    $.simpleWeather({
        location: city,
        woeid: '',
        unit: 'c',
        success: function(weather) {
            var temperatureTemp = parseInt(weather.temp);
            colorSwatchService.weather = +weather.temp + '°' + weather.units.temp + ' ' + weather.currently;
            colorSwatchService.returnSeason(temperatureTemp); //Callback
        }
});

//Callback
returnSeason:function(temperature){
    var date = new Date();
    var month = date.getMonth();

    if (temperature >= 20){
            colorSwatchService.seasons = summerCollectionService;   
    }

    else if (temperature>4 && temperature <20 && (month>7 && month<12)){ 
            colorSwatchService.seasons = fallCollectionService;
    }

    else if (temperature>4 && temperature <20 && (month>1 && month>6)) {
            colorSwatchService.seasons = springCollectionService;
    }

    else if (temperature < 4){
            colorSwatchService.season = winterCollectionService;
    }
}
//AJAX请求
myAjaxCheck:功能(城市){
$.SimpleWither({
地点:北京市,
可悲的是:“,
单位:'c',
成功:功能(天气){
var temperatureTemp=parseInt(天气温度);
colorSwatchService.weather=+weather.temp+''''''天气单位.temp+''''+天气当前;
colorSwatchService.returnSeason(temperatureTemp);//回调
}
});
//回拨
返回季节:功能(温度){
变量日期=新日期();
var month=date.getMonth();
如果(温度>=20){
colorSwatchService.seasons=夏季采集服务;
}
否则,如果(温度>4个月和7个月和4个月和1个月和6个月){
colorSwatchService.seasons=springCollectionService;
}
否则,如果(温度<4){
colorSwatchService.season=冬季采集服务;
}
}
当前的工作重点: 为了在AJAX请求后更新视图,我在变量上使用$watch,在AJAX请求完成后强制使用$digest循环。这会变得很混乱,我认为这不是正确的方法

问题: 在我的AngularJS代码中有没有更优雅的方法来实现$.SimpleWather AJAX请求? 例如,我知道当从URL获取数据时,有$http,它将调用$digest循环本身


您的意见是什么?

您可以将他们的调用封装在$q promise的angular版本中,并通过创建angular ServicesOry将其公开。我对这一切都很陌生。您能发布您描述的代码片段吗?我阅读了$q AngularJS文档,但我不确定我知道您的意思。谢谢!