CodeIgniter Forums
[split] Ajax library? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: [split] Ajax library? (/showthread.php?tid=61289)

Pages: 1 2


[split] Ajax library? - paysalkharis - 04-06-2015

i think we must have ajax library.


RE: [split] Ajax library? - sv3tli0 - 04-06-2015

My personal experience showed that such class is pointless.
The framework should just support different predefined Response types as: html, text, xml, json.
Example:
PHP Code:
$data = array(1=>'ok');
echo 
Response::json($data); 



RE: [split] Ajax library? - albertleao - 04-06-2015

(04-06-2015, 10:14 PM)sv3tli0 Wrote: My personal experience showed that such class is pointless.
The framework should just support different predefined Response types as: html, text, xml, json.
Example:

PHP Code:
$data = array(1=>'ok');
echo 
Response::json($data); 

Yes. That would be niceĀ 


RE: [split] Ajax library? - salain - 04-06-2015

(04-06-2015, 10:14 PM)sv3tli0 Wrote: My personal experience showed that such class is pointless.
The framework should just support different predefined Response types as: html, text, xml, json.
Example:

PHP Code:
$data = array(1=>'ok');
echo 
Response::json($data); 

+1


RE: [split] Ajax library? - silentium - 04-06-2015

Would be nice if the framework supported RESTful services better out of the box. Like different response types as suggested above and CSRF support for more request types that just POST, as I asked about here http://forum.codeigniter.com/thread-1395.html


RE: [split] Ajax library? - nasser.man - 04-07-2015

i am really new in CI but i can use jquery ajax and jquery.form, and is enough for me,


RE: [split] Ajax library? - dmyers - 04-08-2015

I think we could add some support for outputting JSON/Ajax

I have extended output.php already (MY_Output.php) to provide a "nocache" method and json method.

Then I only need to use $this->output->json($json); in my controller

For the XML's maybe a $this->output->xml($xml); would be nice?

As for the RESTful stuff I have also extended the router to provide additional REST methods (maybe not the best approach for everyone but it's a idea)

For example

class exampleController extends rest_controller {
public function dosometingAction() {} /* default GET */
public function dosomethingPostAction() {}
public function dosomethingDeleteAction() {}
public function dosomethingPutAction() {}
}

I know the route.php config now supports REST but I'm just not into manually adding 8+ methods for every single controller CRUD = Cx3 Rx1 Ux3 Dx1 minimum .

DMyers


RE: [split] Ajax library? - blocSonic - 04-10-2015

Controllers should be able to detect request types... including Ajax requests.


RE: [split] Ajax library? - albert.freeman - 04-13-2015

This is a problem for the developer, not the framework.


RE: [split] Ajax library? - mwhitney - 04-14-2015

(04-10-2015, 05:05 PM)blocSonic Wrote: Controllers should be able to detect request types... including Ajax requests.

How do you suggest the controller detect an AJAX request? HTTP_X_REQUESTED_WITH (the server variable checked by $this->input->is_ajax_request()) represents a non-standard header sent (or not) by the client to indicate an AJAX request, but (especially as a non-standard header), there is no requirement for that header to be present alongside an AJAX request.

From the server's perspective, there is otherwise no difference between an AJAX request or a normal request. For this reason, it's largely up to the developer to create a good API for their site and stick to it. If someone sends a non-AJAX request to a method which was designed to only handle AJAX requests, they should be expected to handle the returned data correctly, rather than expecting the server to detect that they didn't use an XmlHttpRequest (and spelling that out brings up the point that the correct return type for an AJAX request isn't set in stone, either).