I've used this "good old" way to fetch HTML formatted data via Ajax and inject it into the DOM.
http://localhost/ajax-controller/mobile-view/resource/1/
$mobile_view = new View('mobile-view'); // use mobile view
$mobile_view->data = $this->data_array; // add some data to view
$this->response->body($mobile_view); // return formatted HTML
http://localhost/ajax-controller/web-view/resource/1/
$web_view = new View('web-view'); // use normal web view
$web_view->data = $this->data_array; // add some data to view
$this->response->body($web_view); // return formatted HTML
Question is What is the RESTful version of this?
Should I fetch just JSON data via Ajax?
http://localhost/ajax-controller/resource/1/
$this->response->body(json_encode($this->data_array)); // return JSON data
开发者_如何学PythonHow should I handle view / HTML formatting, another ajax request? Or am I missing something?
it is fine to have views in restful services, as determining how to return data. I would suggest passing a url parameter like
http://localhost/ajax-controller/resource/1/?view=mobile
and figuring out how to respond via that parameter
精彩评论