Saltar al contenido

ejemplo de código de método get jquery ajax

Ejemplo 1: jquery ajax get

$.ajax({
    	url: "www.site.com/page",
    	success: function(data){ 
    	    $('#data').text(data);
    	},
    	error: function(){
    		alert("There was an error.");
    	}
    });

Ejemplo 2: solicitud de obtención de jquery

jQuery get() Method
The jQuery get() method sends asynchronous http GET request to the server and retrieves the data.

Syntax:
$.get(url, [data],[callback]);
Parameters Description:

url: request url from which you want to retrieve the data
data: data to be sent to the server with the request as a query string
callback: function to be executed when request succeeds
The following example shows how to retrieve data from a text file.

Example: jQuery get() Method
$.get('/data.txt',  // url
      function (data, textStatus, jqXHR) {  // success callback
          alert('status: ' + textStatus + ', data:' + data);
    });
In the above example, first parameter is a url from which we want to retrieve the data. Here, we want to retrieve data from a txt file located at mydomain.com/data.txt. Please note that you don't need to give base address.

Ejemplo 3: como hacer una solicitud ajax javascript

//Change the text of a <div> element using an AJAX //request:
//using JQuery


$("button").click(function(){
  $.ajax({url: "demo_test.txt", success: function(result){
    $("#div1").html(result);
  }});
});



//To send a request to a server, we use the open() //and send() methods of the XMLHttpRequest object:
// Javascript


xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();

//example below
<html>
<body>

<h1>The XMLHttpRequest Object</h1>

<button type="button" onclick="loadDoc()">Request data</button>

<p id="demo"></p>


<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "demo_get.asp", true);
  xhttp.send();
}
</script>

</body>
</html>

Ejemplo 4: jquery get return jquery object

$myspans.eq(2).method();
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *