Giter VIP home page Giter VIP logo

minajax.js's Introduction

minAjax.js

A minimalist Javascript library to perform AJAX POST and GET Request.

Check Pretty Documentation

http://flouthoc.github.io/minAjax.js/

Usage

Getting Started

npm i minajax.js
<script type="text/javascript" src="https://cdn.rawgit.com/flouthoc/minAjax.js/master/minify/index.min.js"></script>

Regular

  minAjax({
    url:"test.php",//request URL
    type:"GET",//Request type GET/POST
    //Send Data in form of GET/POST
    data:{
      name:"batman",
      profession:"detective",
      worth:"Rich",
      company:"Wayne Enterprises"
    },
    //CALLBACK FUNCTION with RESPONSE as argument
    success: function(data){
      alert(data);
    }

  });
  

This is example to use minAjax() , these are the frequent arguments which are usually passed for request to take place there are some optional arguments i'll explain them below.

Compulsory Arguments

url:
  url:'Path or Link to Server Side.'
type:
  type:'GET or POST'

Optional Arguments

data:
  data:{
          param1:value1,
          param2:value2,
          param3:value3,
          param4:value4,
          //also send Arrays
          foo2:["bar2","bar 3","bar+4"]
          //and blah blah as many param as things support.
          }
success:
  success: function(data){
          alert(data);
          //function to be executed on true response with response TEXT as argument.
          }

Execution of Callback function on valid response is totally optional , function can take Response text and Response Status as arguments to process on client side.

method:
method:'True For Asyn and False for Non-Async | By default it is True'

By Default Method will be True i.e Async calls . You Can Leave This

debugLog:
debugLog:'True to enable Debug Console Logs | By Default it is False'

By Default Method will be False | You Can Leave This

Example with all arguments

minAjax({
    url:"test.php",//request URL
    type:"GET",//Request type GET/POST
    //Send Data in form of GET/POST
    data:{
      name:"Superman",
      secretname:"Clark Kent",
      profession:"reporter",
      worth:"poor",
      company:"Daily Planet"
    },
    method:"true",
    debugLog:"true",
    //CALLBACK FUNCTION with RESPONSE as argument
    success: function(data){
      alert(data);
    }

  });
  

Fork it , Create Pull

@flouthoc (http://twitter.com/flouthoc)

minajax.js's People

Contributors

argunner avatar fgrehm avatar flouthoc avatar kingchung avatar mc-zone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minajax.js's Issues

Retrieving Data

On my pull request, I added a JSON feature, but I saw in the object syntax, there's the data attribute. However, that's only for sending. Is there something that the user has to set to specify the data from the XML/JSON? Like if I wanted to get/parse the data from this .json file.

{
"txt": "This is an example of using JSON!"
}

It may be easier to answer if there's only one string or data type, but when there's more the request will have to be more detailed.

Multiple Requests

Because this library used an object to register an AJAX request, what happens if there are more than one request? It may clog up the script. Unfortunately, I am not able to find the answer myself without doing several things, because I try to make my code all client-side and I only have one RPi that's in use. Anyhow, this raises two questions in my mind:

  1. Should this whole repo be based around a function with multiple parameters instead of an object with properties?

  2. If we continue to leave it as an object, would it be possible if we made a loop that goes through all the AJAX requests as an array, making the syntax for properties like config[i].method (for example)?

Does the library have an error function?

I am using minAjax to make a call to my server but can't seem to find the parameter to allow for error callback (on 404, 500 etc). Is this supported or are then plans to support this?

Does it support PUT/DELETE/HEAD requests?

I think it should support the other types of requests too, including PUT, DELETE, HEAD, OPTION, etc. These methods are used in any typical RESTful web API. What's your take on this @argunner?

If it supports all the HTTP verbs already, its better to update the README.

Functionize

I see that there are some benefits to having an object put inside of a function, but I found out that you do not need to have all the parameters for a function to work fine. It seems like it would be a simple transition to apply this, and by doing it we can have set default values without using a bunch of if statements.

Here's something I whipped up for you guys to see as an example of what I mean.
https://www.w3schools.com/code/tryit.asp?filename=GBTZGOTGM0BD

Fetch

Because of the new update incorporating the fetch() method, I believe it is crucial for us to begin working on the development of this. It is able to get around CORS and deliver information with much more ease than AJAX.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.