jQuery AJAX get() method

In this article, we will discuss about the ajax .get() method in jQuery.

jQuery AJAX get() method initiates an asynchronous request using the HTTP GET method.
 

Example of using ajax get() method with xml in jQuery

 
In this example, we will make an ajax call to Google Map api for an address.

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
var url = 'https://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false';
$.get(url, function(response) {
  document.getElementById("getresponse").innerHTML = $(response).find('formatted_address').text();
});
</script>
</head>
<body>
<h3>
Address
</h3>
<p id="getresponse">
  Fetching address from Google map
</p>
</body>
</html>

 


 

Example of using ajax get() method with json in jQuery

 
In this example, we will make an ajax call to Google Map api for an address.

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
var url = 'https://api.github.com/users/topjavatutorial/repos';
$.get(url, function(response) {
  document.getElementById("getresponse").innerHTML = response[0].html_url;

  $.each(response, function(index, element) {
    document.getElementById("getresponse").innerHTML += "<br/>" + element.html_url;
  });
});

</head>
<body>
<h3>
TopJavaTutorial GitHub repositories
</h3>
<p id="getresponse">
  Fetching JSON data TopJavaTutorial GitHub repositories
</p>
</body>
</html>

 

 

© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

Leave a Reply.. code can be added in <code> </code> tags