Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery Ajax POST with PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 438
    Comment on it

    In jquery we have function named ajax() which have two arguments such as url and settings.
    Settings are a set of key/value pairs that configure the ajax request. This argument is optional. We are going to take an small example to understand the functionality.

    <html>
    <head>
    <style type="text/javascript">
    jQuery(document).ready(function(){
    
    var req_url = "http://www.example.com/client.php";
    var req_data = {
           'pass_val':1
    
    };
    jQuery('#process_req').click(function(e){
    e.preventdefault();
    ajax({
            url:req_url,
            data:req_data,
            type:'post',
            success:function(response){
                console.log(response);
            }
    
    });
    });
    });
    </script>
    </head>
    <body>
    <a href="#" id="process_req">Process the ajax request</a>
    </body>
    </html>
    

    In above example, we are passing a requested data to the mentioned url and we will get the response in success part.
    There are many different type of settings pairs. Please have a look.

    A) async (default: true) : If it is true then multiple ajax requests can process in same time otherwise only one request will be process or request will be process one by one, it is known as synchronous process.

    B) beforeSend : it will call a function before sending the ajax request.

    C) cache (default: true, false for dataType 'script' and 'jsonp') : When its value is false then it will force the page not to cached in web browser.

    D) complete : It will call a function when ajax request finish.

    E) data: It will send the data to the server.

    F) dataType : It is a data/response format return from server. Its values can be xml,html,jsonp,text,script

    G) error : It will call a function if request fails

    H) method/type (default: 'GET') : it is method of data passing to server.

    There are many more settings pairs as well.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: