PDA

View Full Version : ExtJs with ASP.NET Single Page Application



haripradhan
17 Jul 2014, 7:36 AM
I wanted to use ExtJs MVC in ASP.NET (http://asp.net/) Single Page Application template provided by Visual Studio 2013 and the template uses protected Web API. Now I am stuck in one problem. The problem is that ASP.NET (http://asp.net/) authorizes the user before calling protected web api by passing in a Bearer Authorization Header. Sample example using jquery is

// Make a call to the protected Web API by passing in a Bearer Authorization Header
$.ajax({
method: 'get',
url: app.dataModel.userInfoUrl,
contentType: "application/json; charset=utf-8",
headers: {
'Authorization': 'Bearer ' + app.dataModel.getAccessToken()
},
success: function (data) {
self.myHometown('Your home town is : ' + data.hometown);
}
});

Could anyone help me doing the same work using ExtJS. I am using Extjs version 4.2.1.

Thanks.

israelroldan
24 Jul 2014, 3:38 AM
This would be the equivalent on Ext JS:


Ext.Ajax.request({
url: app.dataModel.userInfoUrl,
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Bearer " + app.dataModel.getAccessToken()
},
success: function(response) {
var data = Ext.decode(response.responseText);
self.myHometown('Your home town is : ' + data.hometown);
}
});

More info here: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.Ajax-method-request