jQuery ajax()

jQuery ajax() method allows you to perform an AJAX (asynchronous HTTP) request.It was existing since version 1.0.


$.ajax(URL [, settings ])


  • URL:specifies url you wish to load.
  • settings:All settings are optional.
    • accepts:Content type sent in the request header that tells the server what kind of response it will accept in return.
    • async:By default, all sent request are asynchronous.
    • data:Data to be sent to the server when performing the Ajax request.
    • error:A function to be called if the Ajax request fails.
    • success:A function to be called if the Ajax request succeeds.
    • password:specifies a password to be used in an HTTP access authentication request.


change div data by jQuery ajax().

<!DOCTYPE html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery ajax() Example </title>
<div id="txt"><h2>Ajax Content</h2></div>
<button>Change Content</button>
type: "POST",
url: "ajax.php",
success: function(msg)
error: function(jqXHR, textStatus){
$("#txt").html("Request failed: " + textStatus);