A jQuery plugin for make your ajax request's error and success messages auto handled.

Overview

sweetAjax

A jQuery plugin for make your ajax request's error and success messages auto handled.

Installation

sweetAjax plugin has built on jQuery-ui widget factory so after adding jQuery to your html file you also need to add library called jQuery-ui. sweetAjax uses sweetAlert2 for handling error and success messages so also you need to add sweetAlert2 too.

Dependencies

">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" referrerpolicy="no-referrer">script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer">script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js" integrity="sha512-AA1Bzp5Q0K1KanKKmvN/4d3IRKVlv9PYgwFPvm32nPO6QS8yH1HO7LbgB1pgiOxPtfeg5zEn2ba64MUcqJx6CA==" crossorigin="anonymous" referrerpolicy="no-referrer">script>

Simple Usage

 $.sa.sweetAjax({
    url: "/order/count/deneme",
    type: "POST",
    dataType: "json",
    data: {deneme:"deneme"},
    autoAlert:true,
    redirect: true,
    redirectURL:"/login"
});

sweetAjax can get every option $.ajax can it's actually work as wrapper built on $.ajax, also you can use chainable methods like done, error which comes from $.ajax prototype. Top on that sweetAlert comes with 3 additional options;

  • autoAlert: If this option set as true it means that all types of messages (success,error,parserror) will show as native browser alert on page which ajax invoked.
  • redirect: If this option set as true it means that if your response has status code of 401 it's gonna redirect to login page you determined in redirectUrl paramater.
  • redirectURL: Set your login page url if you were set redirect option as true. (You don't need to add your full url plugin itself will add your domain.)

Other Options

  • sweetAlert: If it's not set or set as false, plugin will show messages on native alert which browser's api provided.
  • sweetAlertOptions: It can get what sweetAlert2 plugin can get as an object.
  • notShow: If you want to prevent one of them (success,error,parserror) you can set as key in an object and set as false.
notShow:{
    success:false,
}
  • defaultErrorFields: sweetAjax accepts 3 default parameter from your json responses, you can override their keys with this option if you want to sent messages with different keys.
defaultErrorFields:{
    heading: "heading",
    message: "message",
    type: "type",
}
  • serverError: sweetAjax has default error messages for problems caused by server, you can override that with this option. (That default messages doesn't valid for every 500 status code error, sweetAjax accepts parserrors as serverError for instance it can caused by syntax error from your backend code.)
serverError:{
    heading: "Internal Server Error",
    message: "Try again, if it  continues contact with IT team.",
    type: "error",
}

Callbacks

  • afterSweetAlert: As name tells itself, it's triggered after sweetAlert invoked. It's exactly same with Swal.fire().then(() => {})
You might also like...

Download and extract files

download Download and extract files See download-cli for the command-line version. Install $ npm install

Dec 21, 2022

Full-featured, middleware-oriented, programmatic HTTP and WebSocket proxy for node.js

rocky A multipurpose, full-featured, middleware-oriented and hackable HTTP/S and WebSocket proxy with powerful built-in features such as versatile rou

Nov 24, 2022

A fully-featured Node.js REST client built for ease-of-use and resilience

A fully-featured Node.js REST client built for ease-of-use and resilience

flashheart A fully-featured Node.js REST client built for ease-of-use and resilience flashheart is built on http-transport to provide everything you n

Jun 21, 2022

Bearer provides all of the tools to build, run and manage API integrations.

Bearer provides all of the tools to build, run and manage API integrations.

Bearer - The API Integration Framework Bearer provides all of the tools to build, run and manage API Learn more Archive Status Bearer JS has been arch

Oct 31, 2022

A collaborative Whiteboard powered by the [matrix] protocol and infrastucture.

A collaborative Whiteboard powered by the [matrix] protocol and infrastucture.

TheBoard A collaborative Whiteboard powered by the [Matrix] protocol and infrastructure. Table of Content: Introduction DISCLAIMER How this project ca

Dec 23, 2022

Very very very powerful, extensible http client for both node.js and browser.

ES-Fetch-API δΈ­ζ–‡ | English Very very very powerful, extensible http client for both node.js and browser. Why should you use ES-Fetch API? Still using a

Dec 12, 2022

Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol

πŸ”Ž Mc Server Status Async node.js implementation of the UDP Minecraft Server Query Protocol and TCP Minecraft Server List Ping Protocol. Also availabl

Nov 10, 2022

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Jan 2, 2023

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Highly sophisticated proxy used for evading internet censorship or accessing websites in a controlled sandbox using the power of service-workers and more! Easy deployment version (Node.js)

Ultraviolet-Node The deployable version of Ultraviolet, a highly sophisticated proxy used for evading internet censorship or accessing websites in a c

Apr 15, 2022
Releases(v1.0.0)
Owner
Eren Sertkaya
LAMP stack enthusiast.
Eren Sertkaya
Ajax for Node.js and browsers (JS HTTP client)

superagent Small progressive client-side HTTP request library, and Node.js module with the same API, supporting many high-level HTTP client features T

Sloth 16.2k Jan 1, 2023
Library agnostic in-process recording of http(s) requests and responses

@gr2m/http-recorder Library agnostic in-process recording of http(s) requests and responses Install npm install @gr2m/http-recorder Usage import http

Gregor Martynus 4 May 12, 2022
Wrap native HTTP requests with RFC compliant cache support

cacheable-request Wrap native HTTP requests with RFC compliant cache support RFC 7234 compliant HTTP caching for native Node.js HTTP/HTTPS requests. C

Luke Childs 259 Dec 20, 2022
Open AI Codex Code Auto Complete Visual Studio Code extension

OpenAI Codex Code Autocomplete "OpenAI Codex Code Autocomplete" extension helps connect to Codex API provided you have access to Codex API and have AP

gittmaan 4 Dec 28, 2022
NodeJS app to dynamically update your twitter header with AP Dhillon's lyrics

header-dhillon A NodeJS app that dynamically updates your twitter header with 2 lines of random lyrics from any random track by the punjabi artist AP

Raj Shankar Tiwary 4 Jul 25, 2022
A vscode extension to connect your android phone wirelessly to PC.

ADB-QR README Connect Your Android device with your PC wirelessly for debugging with the help of this extension. Requirements Android Version : 11+. A

Aakash Pamnani 6 Oct 14, 2022
Hello! Welcome to Our own Live Code Editor 2!! This is supported tabs and full-screen editing, Console, tabs and more are coming. We uses this one in our all tutorials. Made by @E-Coders & @Genius398

Live Code Editor 2 Hello! this is our live code editor an another second release version of our main Resporibity. This have style as tabs and more fea

Educational Websites 5 Nov 18, 2021
Promise based HTTP client for the browser and node.js

axios Promise based HTTP client for the browser and node.js New axios docs website: click here Table of Contents Features Browser Support Installing E

axios 98k Dec 31, 2022
HTTP server mocking and expectations library for Node.js

Nock HTTP server mocking and expectations library for Node.js Nock can be used to test modules that perform HTTP requests in isolation. For instance,

Nock 11.9k Jan 3, 2023
🌐 Human-friendly and powerful HTTP request library for Node.js

Sindre's open source work is supported by the community. Special thanks to: Human-friendly and powerful HTTP request library for Node.js Moving from R

Sindre Sorhus 12.5k Jan 9, 2023