Monday, 05 August 2019 16:16

how to use jquery ajax

Written by 
Rate this item
(0 votes)

The jquery ajax() method is used to do AJAX (asynchronous HTTP) request. As we  know ajax is used to do things without loading the page. 

 Following is a example of a simple jquery ajax definition and usage - 

code in head section of the html document - 

$("#our_button").click(function(){

  $.ajax({ url: "external_content.txt", success: function(result) {

    $("#our_div").html(result);

  }});

});

Code in body section of html document - 

<div id="our_div">Let jquery ajax change this text </div>

<button id="our_button">bring external content</button> 

here when the our_button clicked, it shows the external content of a txt file in the our_div element using ajax. The parameters in the ajax request are the name: value pairs. there are many parameters, search through google.com.

 

Read 1347 times Last modified on Monday, 05 August 2019 16:28
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.