Class for Ajax applications

Intro

Let me introduce my small class for creating Ajax based applications.

Mezon Framework provides simple class for creating ajax applications. This class uses all functionality of the Mezon Application Class also provides usefull functio…


This content originally appeared on DEV Community and was authored by alexdodonov

Intro

Let me introduce my small class for creating Ajax based applications.

Mezon Framework provides simple class for creating ajax applications. This class uses all functionality of the Mezon Application Class also provides usefull functionality:

Installation

Just print in console

composer require mezon/ajax-application

And that's all )

Exception handling

For better debugging exception handling is performed in a special way. If the ajax request will be failed to process, then on the front end you will get JSON object with fields:

  • code - code of the occured error;
  • message - textual description of the occured error;
  • call_stack - call stack for the call wich lead to the error.

Finishing request processing

After finishing request processing you can mark it as successfull:

function ajaxRequestSuccess(): void

Wich will return {"code": 0}

Or return any other result:

function ajaxRequestResult($result): void

In this case $result will be encoded in JSON and outputted.

Or in case of the error you can call

function ajaxRequestError(string $message, int $code = - 1): void

Wich will return object {"code": $code, "message": "message"}

Learn more

More information can be found here:

It will be great if you will contribute something to this project. Documentation, sharing the project in your social media, bug fixing, refactoring, or even submitting issue with question or feature request. Thanks anyway ) I'll be very glad if you'll press "STAR" button )


This content originally appeared on DEV Community and was authored by alexdodonov


Print Share Comment Cite Upload Translate
APA
alexdodonov | Sciencx (2022-09-26T20:51:28+00:00) » Class for Ajax applications. Retrieved from https://www.scien.cx/2021/04/30/class-for-ajax-applications/.
MLA
" » Class for Ajax applications." alexdodonov | Sciencx - Friday April 30, 2021, https://www.scien.cx/2021/04/30/class-for-ajax-applications/
HARVARD
alexdodonov | Sciencx Friday April 30, 2021 » Class for Ajax applications., viewed 2022-09-26T20:51:28+00:00,<https://www.scien.cx/2021/04/30/class-for-ajax-applications/>
VANCOUVER
alexdodonov | Sciencx - » Class for Ajax applications. [Internet]. [Accessed 2022-09-26T20:51:28+00:00]. Available from: https://www.scien.cx/2021/04/30/class-for-ajax-applications/
CHICAGO
" » Class for Ajax applications." alexdodonov | Sciencx - Accessed 2022-09-26T20:51:28+00:00. https://www.scien.cx/2021/04/30/class-for-ajax-applications/
IEEE
" » Class for Ajax applications." alexdodonov | Sciencx [Online]. Available: https://www.scien.cx/2021/04/30/class-for-ajax-applications/. [Accessed: 2022-09-26T20:51:28+00:00]
rf:citation
» Class for Ajax applications | alexdodonov | Sciencx | https://www.scien.cx/2021/04/30/class-for-ajax-applications/ | 2022-09-26T20:51:28+00:00
https://github.com/addpipe/simple-recorderjs-demo