Some background: I came from a .Net environment where we had to use MVVM in all of our projects to separate the view from the viewmodel. Now that I'm working on my own personal PHP project I decided to use the same design and separate the view and viewmodel.
So on the view I create a viewmodel object and call background functions when necessary and in the view the code is only to provide the display.
Example:
view.php
<?php
include('viewmodel.php');
$vm = new viewmodel.php();
if(some condition)
{
$vm->doSomething();
}
?>
<html>
<body>
//some form code
</body>
</html>
viewmodel.php
<?php
//includes
class viewmodel
{
function viewmodel()
{
}
function doSomething()
{
}
}
?>
Now that I've learned jQuery I want to use it to make my pages more dynamic, have less traffic back and forth to the server and less need for page refreshing.
I've seen calls like this that allow jQuery to call a php page with some some post data:
$.ajax({ url: '/my/site',
data: {action: 'test'},
type: 'post',
success: function(output) {
alert(output);
}
});
However this is no longer Object Oriented Design and I would have to remove all the class definitions from my viewmodels for this to work.
Is there any way for jQuery to make those calls to the viewmodel or does using jQuery mean you have to return to a procedural style of programming?