Refactor Ajax view logic out of SetOSView

This should make it more useful (in the future).