Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ABTanjir/easy-ajax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyajax

easyajax jQuery Plugin Live Exaple

Dependency

-jQuery

Good to have

This plugins are not required but if you want to show toastr notification & sweetalert just integrate toastr & sweetalert plugin easy ajax will automatically use those instead of alert

-bootstrap

-toastr

-sweetalert

    <link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.js"></script>

Intrgrate easyajax

    <script type="text/javascript" src="../easyajax.js"></script>

Select dom and initiate easyajax

    $('.ajax').easyajax();

easyajax callback functions

$('.ajax').easyajax({
    autoEnable: "[false || time in mili second]",
    after_render: function(elem, data){
        // code
    },
    before_ajax: function(elem){
        console.log('before');
    },
    after_ajax: function(elem, data){
        console.log('after');
    },
    error_ajax: function(elem, xhr){
        console.log(xhr);
    }
});

If you don't want to use toastr or want to manage your notification

$('.ajax').easyajax({
    notification: function(elem, data){
        //code
        alert(data.message);
    }
});

Form markup

<!-- just add a class *ajax* in your form element-->
<form action="" class="ajax">

<!-- if you want to use validation-->
<form action="" class="ajax needs-validation" novalidation="true">

<!-- if you want to force ignore validation-->
<form action="" class="ajax ignore_validation">

href markup

if you want a link (href tag) to be submitted as ajax just simply add the class ajax in it as you have initiates .ajax dom with easyajax

<a href="http://sample.com/ajax/get" class="ajax" >
<!-- if you want to show a confirm alart -->
<a href="http://sample.com/ajax/get" class="ajax" data-confirm="are you suere you are doing this?" >

Responses with action

response must be a json object

{
"status":"success", 
"message":"Success message."
}

status must be [success, error, warning, info] message this can be html or plain string [N|Solid

if you use sweetalert confirmation message will trigger swal confirmation box [N|Solid

There are few interesting action you can take only with response

Below response will remove closest class_name dom

{
"status":"success", 
"message":"Deleted item successfully.",
"remove":".class_name"
}

If you want to refresh or reload a part of your html page.

this will rerender the dom (#id_name) only after ajax request.

{
"status":"success", 
"message":"Deleted item successfully.",
"rerender":"#id_name"
}

If you want to refresh the page

this response will refresh your page after 3 sec

{
"status":"success", 
"message":"Deleted item successfully.",
"refresh":"3000"
}

empty an html dom after ajax success/error

{
"empty":".class_name"
}

trigger form reset

{
"reset":"true"
}

About

Easy ajax helper for jquery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published