SuperPlan(13)Winner Seller Server - JSONP Basic Auth

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

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...