All Projects β†’ serkanyersen β†’ AjaxHandler

serkanyersen / AjaxHandler

Licence: other
ASimple PHP Class to help handling Ajax Requests easily

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to AjaxHandler

Wretch Middlewares
Collection of middlewares for the Wretch library. 🎁
Stars: ✭ 42 (+40%)
Mutual labels:  ajax, request
Reqwest
browser asynchronous http requests
Stars: ✭ 2,918 (+9626.67%)
Mutual labels:  ajax, jsonp
vue-methods-promise
Let Vue methods support return Promise
Stars: ✭ 35 (+16.67%)
Mutual labels:  ajax, request
miniAjax
πŸš€A mini Ajax library provides Ajax, jsonp and ready features for simple web applications.
Stars: ✭ 67 (+123.33%)
Mutual labels:  ajax, jsonp
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+5820%)
Mutual labels:  ajax, callback
Fable.simplehttp
Http with Fable, made simple.
Stars: ✭ 57 (+90%)
Mutual labels:  ajax, request
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (+50%)
Mutual labels:  ajax, request
Vue Api Request
Control your API calls by using an amazing component which supports axios and vue-resource
Stars: ✭ 116 (+286.67%)
Mutual labels:  ajax, request
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+7516.67%)
Mutual labels:  ajax, request
sa
Simple Ajax: a lightweight library to make AJAX requests
Stars: ✭ 13 (-56.67%)
Mutual labels:  ajax-request, ajax
seenreq
Generate an object for testing if a request is sent, request is Mikeal's request.
Stars: ✭ 42 (+40%)
Mutual labels:  request
AMS
Attendance management system made my me, which I use for taking attendance.
Stars: ✭ 13 (-56.67%)
Mutual labels:  ajax
kubernetes-basico
Demonstração dos componentes do Kubernetes
Stars: ✭ 26 (-13.33%)
Mutual labels:  utility
actlist
πŸ“¦ Actlist is a utility platform to execute your own action list easily and simply.
Stars: ✭ 85 (+183.33%)
Mutual labels:  utility
WaterPipe
URL routing framework, requests/responses handler, and HTTP client for PHP
Stars: ✭ 24 (-20%)
Mutual labels:  request
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+243.33%)
Mutual labels:  callback
fhash
fHash - an open source files hash calculator for Windows and macOS
Stars: ✭ 222 (+640%)
Mutual labels:  utility
larashop55
Shopping cart website in Laravel 5.5 with Ajax
Stars: ✭ 51 (+70%)
Mutual labels:  ajax
sora
A simple library to display images in Jupyter notebooks
Stars: ✭ 15 (-50%)
Mutual labels:  utility
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (+10%)
Mutual labels:  callback

Don't write that switch again.

Are you tired of writing the same Ajax handler code over and over again on your each project? There are always the same steps and same problems, is it handling headers correctly? Will it work with jQuery? Status Codes? JSONP?

Well, I've collected all the code pieces together and created the AjaxHandler. It's a very simple PHP Class which you can inherit and create your own Ajax handlers easily.

Features

Here is a list of features Ajax Handler provides

  • Unified Output Your every Ajax request will produce a standard JSON output, so your client code will be simpler and understandable. Outputs are only handled by ::error and ::success methods, You'll never have to use json_encode when outputting.
  • Error Handling AjaxHandler will automatically catch exceptions and PHP errors and handle them for you. You can customize error messages and changes status codes
  • JSONP Support Ajax handler will automatically handle requests with callback parameters, you can customize the callback name and type
  • Clean Code Object Oriented design will let you easily tear apart your code into separate files, This is especially good for Backbone like MVC projects
  • Stats Ajax handler will keep duration of your each request and return it to you, so you can easily measure your codes performance
  • Very Simple Code Ajax Handler's code is very simple and you can easily customize it according to your needs.
  • It's All Free Ajax Handler is an MIT licensed piece of code so you can use it own your own projects

Here is a very basic example of AjaxHandler in Use lets say this is person.php

<?php
include "AjaxHandler.php";
class Person extends AjaxHandler{
    
    /**
     * Private function will not be accessed from outside
     * @return Mongo Collection
     */
    private function getMongo(){
        $m = new Mongo();
        $db = $m->selectDB('main');
        $cl = $db->selectCollection('people');
        return $cl;
    }

    /**
     * All I write here is the code
     * I didn't write anything to handle output
     * If the code gives an exception, ajax 
     * handler will return error, If Everything is successfull
     * Standart success message will be returned
     * @return [type] [description]
     */
    public function createPerson(){
        
        $db = $this->getMongo();
        
        $result = $cl->save(array(
            "name" => $this->get('name'),
            "age"  => $this->get('age')
        ));
    }
    
    /**
     * Here is the code for handling your own messages
     * @return [type] [description]
     */
    public function getPersonDetails(){
        $db = $this->getMongo();

        $cursor = $db->fetch(array('name' => $this->get('name')));

        if($cursor->count() === 0){
            // Will produce an error
            // {"success": false, "error": "Person cannot be found"}
            $this->error('Person cannot be found');
        }else{
            // Will giveout a JSON success message
            // {
            //   "success": true, 
            //   "details":{"name":"john", "age":"29"}, 
            //   "message":"Operation successful"
            // }
            $this->success(array(
                "details"=>$cursor->first()
            ));
        }
    }
}
?>

You can make requests with jQuery easily

$.ajax({
    url:'person.php',
    data:{
      action: 'createPerson',
      name: 'john',
      age: 29
    },
    dataType:'json',
    complete: function(res){
        if(res.success){
            alert('User Saved');
        }else{
            alert('Error: '+ res.error);
        }
    }
});

I'll write a more detailed documentation soon.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].