How to use jQuery Ajax Request/Method?

JQuery Ajax Method

JQuery Ajax Method is used to perform an asynchronous HTTP (Ajax) request. The jQuery library provides a few different methods to perform AJAX calls, although here we’ll look at the ajax method, which is the most often used.

Take a look at the following example.

<script type="text/javascript">
    $(".ajaxBtn").click(function(){
        $.ajax({
            url: "/test/url-to-post.php",
            dataType: "json",
            type: "POST",
            data: {"id":"1"},
            success: function (data) {
                alert(data);
            },
            error: function() {
                alert('Error.');
            }
        });
    });
</script>

Don’t forget to use jquery CDN to make this code work.

<html lang="en">
<head>
  <title>JQuery Ajax Demo</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
...
</body>
</html>

You can get more details about this topic from here.
To get to know more about other JQuery topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply

Share