jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
- $.ajax({ async:true, url:url, success: function(v), error: function(xhr,status,err), timeout:3000});
- $.ajax with formdata
- $.get( url, function(data,status) {} )
- Get POST method result from a server in jQuery
- jQuery Example: $.ajax() example to load external content and display on the div area in HTML
- jQuery Example: get JSON feed directly
- jQuery Example: Run JavaScript code when the HTML page gets ready
- Pop up a floating window in HTML
- Showing and Hiding content in jQuery
Example 1) Hide all the content in <p> tag based in jQuery.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> <p>Click me away!</p> <p>Click me too!</p> </body> </html>
Example 2) Call a URL, and show its response
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> var fd = new FormData(); fd.append( 'file', input.files[0] ); jQuery.ajax({ url: 'http://example.com/script.php', type: 'POST', data: fd, processData: false, contentType: false, async: false, success: function(response){ alert(response); } }); </script>
Example 2) Call a URL, and use its Json object
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> var fd = new FormData(); fd.append( 'file', input.files[0] ); jQuery.ajax({ url: 'http://example.com/script.php', type: 'POST', data: fd, processData: false, contentType: false, async: false, success: function(response){ var obj=JSON.parse(response); alert( obj.result[0].message); } }); </script>