Possible Duplicate:
MVC ajax calls – where to handle them?
I have a framework which the overall view is as below:

This picture is from PHP 5 Social networking book, I don’t have the Page Object part. I dont have any problem with simple javascript/jQuery statements, but when it comes to JSON or Ajax where I need to fetch data then I’m confused! Beacause in JSON we need to put the url part. In an MVC there is no direct call. Everything will reach to Front Controller (index.php).
Now the question is how to handle JSON or Ajax requests in MVC? Should I create separate json php files in another directory to handle database connections,etc which is not Object Oriented?
I don’t know which framework you are using but, Zend Framework, for example has a mechanism that allows you to modify the format an action returns it’s data in. In Zend Framework this is called a context switch.
You might want to check out how they implement that feature and see if you can either integrate it into your mvc or model it within your own mvc.
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch
— Edit —
It sounds like your framework does not delegate to controllers? If this is the case I would implement the solution you hinted at in your question and implement scripts that are consumed solely by your Ajax/REST calls.
— Edit —
Right so your front controller dispatches requests to controllers, that being the case I would recommend implementing context switching at the controller level, which will work using the same urls you would use in a standard request but would either read
a) HTTP header info to see what response type you are asking for, which you would set in the AJAX request.
b) send another parameter along in the url something like
format=jsonthat will switch the return type of your action.I would recommend reading the info at the link I posted as it might make things a little bit clearer.