大佬教程收集整理的这篇文章主要介绍了angularjs – 返回JSONP时不执行HTTPpromise,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
window.LOCATIOn = '/stocks/show_stock'
在包装JSONP响应的回调函数中
2)我发表声明:
$LOCATIOn.path '/stocks/show_stock'
这是我的代码(在coffescript中):
#THIS IS THE CALLBACK FUNCTION THAT I SEND WITH THE JSONP requEST window.stock_quote_callBACk = (data)-> console.log data #THIS WORKS AND I CAN SEE THE DATA RETURNED FROM YAHOO window.stock_quote_result = data.results alert 'I am in the callBACk' #THE STATEMENT BELOW DOES NOT WORK EVEN THOUGH I CAN SEE THE ALERT ABOVE window.LOCATIOn = '/stocks/show_stock' angular.module('services').service 'Stocksupplier',($http)-> get_stock = (symbol)-> q = 'SELEct * from yahoo.finance.quotes where symbol in ("'+symbol+'") &format=json& diagnostics=true& env=http://datatables.org/alltables.env& callBACk=stock_quote_callBACk' url = 'http://query.yahooapis.com/v1/public/yql?q='+q $http.jsonp(url).then (data)-> #THE CODE BELOW NEVER EXECUTES EVEN THOUGH RESULT IS RETURNED alert 'This should pop up when result returns' $LOCATIOn.path'/stocks/show_stock' { get_stock: (symbol)-> get_stock(symbol) }
先感谢您.
angular.module('services').service('Stocksupplier',function($http,$LOCATIOn) { var get_stock; get_stock = function(symbol) { var q,url; q = 'SELEct * from yahoo.finance.quotes where symbol in ("' + symbol + '")&'+ 'format=json&'+ 'diagnostics=true&'+ 'env=http://datatables.org/alltables.env&'+ 'callBACk=JSON_CALLBACK '; url = 'http://query.yahooapis.com/v1/public/yql?q=' + q; return $http.jsonp(url).then(function(data) { alert('This should pop up when result returns'); $LOCATIOn.path( '/stocks/show_stock' ); }); }; return { get_stock: function(symbol) { return get_stock(symbol); } }; });
以上是大佬教程为你收集整理的angularjs – 返回JSONP时不执行HTTPpromise全部内容,希望文章能够帮你解决angularjs – 返回JSONP时不执行HTTPpromise所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。