Working with Ajax



[*]Does the submission of yii reload the whole page of it sent the form data and set error on the form via ajax?

[*]How does ajax rendering view work? I would like to have on page and changing that page parts using ajax without reloading the whole page how can I do it?


It depends on the controller action that you are calling with your submission.

The controller can either return a page, in which case you will get a reload,

or it can return a AJAX response in which case your submitting page will process the response and update the page as needed.

For displaying a ‘normal’ view, your controller will collect all the information that you want to display, call the appropriate view file with the information attached as parameters. The view file will format your output, return to the controller, then the controller will send the completed page to the browser.

AJAX will do something like this, but probably will not call any view files. Just return some information as JSON, XML, plain text, or what ever else you create.

It is a somewhat complex process, and there is no simple answer to ‘how do I…’. If you do some googling for ‘AJAX requests with yii2’, you should find some examples.

Most of the work will probably be done with javascript on the browser. Jquery has great AJAX functions.