Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon Ajax

Hi fellows, i've looking for everywhere and everything i founded about phalcon + ajax it's seems to be that ajax request like from a simple form, it has to be done by jquery, there is not an agile, friendly way to handle like ruby on rails does. am i wrong? can you give an example or tutorial? i'm totally newbie in phalcon, i don't wanna look like a stupid, but i really want out of this doubt. Thanks



9.7k
edited Jan '16

http://www.w3schools.com/ajax/default.asp

jquery/angular/whatever js library you use is a wrapper for XMLHttpRequest. This object is what allows the client to call the server to get data. Phalcon most definitely supports listening for the URL you're calling and responding with the correct data.

https://github.com/zhegwood/phalcon.angular.bootstrap

There are a few examples in this repo of ajax calls with Angular. jQuery uses similar get/post requests. You can also use the XMLHttpRequest object if you want, but there are browser differences that are abstracted away by libraries like Angular and jQuery.

so, no? phalcon does not integrates ajax?

http://www.w3schools.com/ajax/default.asp

jquery/angular/whatever js library you use is a wrapper for XMLHttpRequest. This object is what allows the client to call the server to get data. Phalcon most definitely supports listening for the URL you're calling and responding with the correct data.

https://github.com/zhegwood/phalcon.angular.bootstrap

There are a few examples in this repo of ajax calls with Angular. jQuery uses similar get/post requests. You can also use the XMLHttpRequest object if you want, but there are browser differences that are abstracted away by libraries like Angular and jQuery.



9.7k

Phalcon provides the routing and server-side interaction. If that's not what you're asking then I guess I fail to understand your question. AJAX is a client (browser) making a request, the server listening for that request, and returning the data the request asked for. Phalcon definitely has the ability to listen for the request, route the request, and return the data to the client. I have no experience with Ruby so I'm not sure what you're trying to compare.

ok,let's say a form to create a post(like twitter), once have been created the new post should show it without refresh the page, my question is: to send the data to the controller, i have to use jquery? something like: $("buton").click{preventDefault;$ajax{field.val}} because, this seems dying for me, i mean it could be 10 fields in a form, and another cases that i can imaginated it scares me that phalcon doesn't have a native way to handle ajax.

Phalcon provides the routing and server-side interaction. If that's not what you're asking then I guess I fail to understand your question. AJAX is a client (browser) making a request, the server listening for that request, and returning the data the request asked for. Phalcon definitely has the ability to listen for the request, route the request, and return the data to the client. I have no experience with Ruby so I'm not sure what you're trying to compare.

edited Jan '16

Hello,

maybe this is making it more clear. Ajax is handled by a JS Client side component like jQuery, angularJS or just simple native JS...

So if you have a form and wanna make no page reload (like it is common at this times) then u use a jQuery request. 1) This sends a request to the server ... save this form data... 2) the server/phalcon can regonize that this is an ajax request and you business logic is doing the rest and answers with a json response. 3) Ur Client Side code in JS is doing something with the servers response.

Hope thats helping you a little bit. But back to your question there is no nativ Wrapper for Ajax which is generating all that code for you. but you can write this quite simple and also make it dynamic - just need a little bit of thinking and experience.



4.1k
Accepted
answer

Hi I use http://phalcon-jquery.kobject.net/ very simple and useful for generating scripts or rich components (Bootstrap, jQueryUI) on server side.

Usage:

$di->set("jquery",function(){
    $jquery= new JsUtils(array("driver"=>"Jquery"));
     $jquery->ui(new Ajax\JqueryUI());//optional for JQuery UI
    return $jquery;
});

` Regards André

looks fine, but it has little documentation. Thanks for the help

Hi I use http://phalcon-jquery.kobject.net/ very simple and useful for generating scripts or rich components (Bootstrap, jQueryUI) on server side.

Usage:

```php $di->set("jquery",function(){ $jquery= new JsUtils(array("driver"=>"Jquery")); $jquery->ui(new Ajax\JqueryUI());//optional for JQuery UI return $jquery; }); ```` Regards André