i was trying with all the SPA template available with ASP.NET MVC. finally decided to go with Durandal template. It seems to be full filling all my selection criteria:
- html and javascript are in separate file
- html parts, and related JavaScripts are loaded automatically by the framework
- and easy way to load relevant data though activation
- good routing
Durandal tick all the box perfectly. I installed the template and create my first application. Sample works like charm. Shows some images from flicker.
Then To test a sample webservice call to my code, I've added my own WebApi controller and tried same way as flicker call.
But it's not working. I can see in fiddler that it's making the ajax call and a json response is coming back from the server, but for some reason framework is not invoking the promise( response call back). No error is shown. Tried debugging and it's not easy either.
After long try with this and that finally decided to gove durandal http module a ditch and try jquery ajax call directly. i provided the error call back as well and BANG!
Error!
Parsing error.
Because I was simply following the template. I was using the same jsonp data type as used in the flicker call. But my MVC Web API is not returning jsonp. It's json only! :)
So changed the call to http.get and Hurrah!!! all is working.
var that = this;
//debugger;
return http.get('http://localhost:63795/api/projects').then(function (response) {
that.projects(response);
});
var that = this;
//debugger;
return http.get('http://localhost:63795/api/projects').then(function (response) {
that.projects(response);
});
Thanks for sharing!
ReplyDelete