Reusable AJAX Functions (Post/Get)

Today, We want to share with you Reusable AJAX Functions (Post/Get).In this post we will show you Reusing AJAX function multiple times, hear for jquery multiple ajax calls in sequence we will give you demo and example for implement.In this post, we will learn about jQuery Ajax Calls in Web Applications with an example.

Reusable AJAX Functions (Post/Get)

There are the Following The simple About Reusable AJAX Functions (Post/Get) Full Information With Example and source code.

As I will cover this Post with live Working example to develop nested ajax calls, so the some problem with multiple ajax requests for this example is following below.

Also Read :  Find Factorial program in GO Example

Reusable jQuery Ajax ($.ajax) Example

Reusable jquery ajax Function (index.html)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>reusable jquery ajax - pakainfo.com</title>
    </head>
    <body>
	<h3>jQuery Ajax Calls in Web Applications</h3>
<?php 

define("GET_PROTOCOL", ((!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https') || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? "https://" : "http://");

$full_api_server_domain_path = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'blog.dream11.com';
//echo $full_api_server_domain_path;

define("MAIN_PATH", GET_PROTOCOL . $full_api_server_domain_path . '/dream11/img/');
//echo MAIN_PATH;

?>
        
<!-- SCRIPTS -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
    <script>
    function getMainUrl(url) {
        return '<?php echo MAIN_PATH; ?>' + (url || '');
    }

    function doAjaxprocess(url, params, successCallback, errorCallback) {
        $.ajax({
            success : successCallback,
            error : errorCallback,
            data : params,
            url : url,
            type : 'POST',
            dataType : 'json'
        });
    }

    var user_type = "employee";
    doAjaxprocess(
        getMainUrl('do_submit_data_app.php?action=product_insert&user_type=' + user_type), 
        { 
            data : 'abc' 
        }, 
        function(resp) { 
            alert('Success');
            console.log(resp);
        },
        function(errorCallback) {
            alert('display some error');
            console.log(errorCallback);
        }
    );

    </script>
    </body>
</html>

Web Programming Tutorials Example with Demo

Read :

Also Read :  Reusable jquery AJAX requests Multiple Times

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Reusable AJAX Functions (Post/Get).
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.