Knockout.js: first experience

For a project, I have started using Knockout.js.
This is a library to build UIs starting from a data model that is binded to html templates.

To start using the library, there is a list of articles that must be read:

And finally a few notes I have understood:
  • Visible controls only the html style, but you have always the binding.
    If you don't want to bind something (for example because you have null objects), use the if construct
Other links:

JavaScript: console.log error

When working in JavaScript I have done output with console.log, but after that my page was working correctly only in debug mode.

I have found the solution in the page What is console.log and how do I use it?: the reason is that in Internet Explorer up to version 8, console.log is defined only in debug mode.

The solution is to add in your page the following JavaScript code:

   if(!window.console){ window.console = {log: function(){} }; }

JavaScript: how call cross-domain Ajax services

For one big company I have developed a project where I had to call JSON services from client html pages.

The particularity was that the services where hosted in a domain different from the domain of the hosted pages.

I have found some difficulties, and here is a list of tips:

  • Internet Explorer requires the use of the object XDomainRequest
  • if the calling page is served in https, the JSON service has to called in https too
  • the receiving service must accept cross-domain calls and must declare this adding the following header:
          Access-Control-Allow-Origin: *

Some (but not all) of this guidelines is in the article Cross Domain Ajax Request with JSON response for IE,Firefox,Chrome, Safari – jQuery.