Reputation: 4970
Let's say I've decided to try and make a web application where the client is only html and javascript/jquery and I will fetch the data from a json service.
I come from the land of web forms and is now learning and loving mvc and here we have master pages and components like user controls and partial views etc, which enables us to re-use components and structure our code.
How do I do this when I'm using only html and javascript?
I've seen that jquery has the method load()
which loads data from the server. Is this the best approach to achieve what I want? Or is it something out there that I have missed?
Upvotes: 2
Views: 1651
Reputation: 8166
This is a rather big and subjective question.
If you plan to consume your data using JSON the method, what you'd probably want to use is getJSON() which is a wrapper of the more flexible ajax()
.
Then you'll probably need a templating system, to avoid creating and injecting html using javascript (it can become a real mess for every task which is a bit more complex than the trivial ones).
Regarding your application structure you might consider patterns such as MVC, MVP or MVVM. There are several good libraries that allow you to leverage these patterns, but personally I'd recommend to start to play without frameworks, and switch to one of them only when you feel a real need for it, and you grasp at least some basic concepts.
Good luck :)
Upvotes: 1