Invocar PHP con GET mediante jQuery

Este ejemplo hace un submit de tipo GET mediante ajax:


Página html:

<form id='form1'>

<input type='text' size='4' name='item1' />
<input type='text' size='4' name='item2' />
<input type='submit' size='4' id='grabar' value='guardar' />

</form>


<script>
$(document).ready(function() {
$("#form1").submit(function() {
Grabar();
});
});

function Grabar()
{
dataString = $("#form1").serialize();

jQuery.ajax({
  type: "GET",
  url: "grabar.php",
  data: dataString,
  contentType:"text",
  dataType:"text",
  cache: false,
  success: function(response) {    
 alert(response);
  },
  error: function(xx) {
return "";
  }
});
}

</script>


Página PHP:


<?php
echo $_GET['item1'];
?>

No hay comentarios:

Publicar un comentario