加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SuperPlan(13)Winner Seller Server - JSONP Basic Auth

发布时间:2020-12-16 19:22:42 所属栏目:百科 来源:网络整理
导读:SuperPlan(13)Winner Seller Server - JSONP Basic Auth 15. Basic Auth on JSONP Server If we are using the basic auth,we can do the jsonp client like this. Here is the View Controller of Backbone.js …snip... render: function(){ window.logger.
SuperPlan(13)Winner Seller Server - JSONP Basic Auth 15. Basic Auth on JSONP Server If we are using the basic auth,we can do the jsonp client like this. Here is the View Controller of Backbone.js …snip... render: function(){ window.logger.debug("I am going to hit the Nav Bar Template Page."); var widget = this; var navBars = new NavBarsModel(); window.logger.debug(" navBars url = " + navBars.url); navBars.fetch({ data: {},type: 'GET',success: function(data,response,options) { window.logger.debug("NavBarView data = " + data); var compiledTemplate = _.template( htmlTemplate,{ items : data } ); $("#navBar").html(compiledTemplate); },error: function(jqXHR,textStatus,errorThrown) { window.logger.error('error arguments: ',arguments); window.logger.error(jqXHR + " " + textStatus + " " + errorThrown); },complete: function(xhr,textStatus) { window.logger.debug(textStatus); } }); } …snip… Here is the Model Layer of Backbone.js …snip... var Items = Backbone.Collection.extend({ url: '/navbars',parse: function(response) { window.logger.debug("getting NavBars from response=" + response); return response; },sync: function(method,model,options){ options.timeout = 10000; //json mock //options.url = 'http://localhost:9000/data' + "/navbars" + ".JSON"; //options.dataType = 'json'; //jsonp options.dataType = "jsonp"; options.crossDomain = true; options.url = 'http://' + 'customer' + ':' + 'customer' + '@' + 'localhost:9002/v1/sillycat' + '/navbars'; return Backbone.sync(method,options); } }); …snip… It the server side,we also use jsonpwithParameter …snip... pathPrefix(Version / BrandCode) { (apiVersion,brandCode) => authenticate(BasicAuth(new BrandUserPassAuthenticator(dao),"Realm")) { user => path("products") { jsonpWithParameter("callback") { complete(HttpBody(`application/json`,dao.db.withSession { logger.debug("Hitting the URI navbars with apiVersion=" + apiVersion + ",brandCode=" + brandCode) DefaultJsonProtocol.listFormat[NavBar].write(dao.NavBars.all).toString } )) } } } } …snip… It is not nice and pretty to use POST in jsonp. So I will change back to JSON for both the server side and client side. 16. JSON cross domain come soon... 17. Integration(Backbone + Require + Jasmine + Phantom + Grunt + Bootstrap) come soon… References: integration http://hdnrnzk.me/2013/01/10/backbone-requirejs-jasmine-phantomjs-and-grunt/ https://github.com/ghiden/backbone-requirejs-jasmine-phantomjs-grunt-setup superplan 12 http://sillycat.iteye.com/blog/1881952

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读