Hello guys, my first time writing to group...I'm a beginner in jquery and
I'm trying to learn the $.ajax() method. I created a simple form (3 inputs)
and the form should send the data (via ajax) to the page ajax.php which will
return the data to be written in a div (#mensagem), just it.

But I would like to know why *THIS* works:

*$('#form').submit(function() {*
* **  $.post(*
* **'ajax.php', *
* **$('#form').serialize(), *
* **function(data){*
* **  $('#mensagem').html(data);*
* **}*
* **  );*
* **  return false;*
* **});*

and *THIS* doesn't work:

*$('#form').submit(function() {*
* **  $.ajax({*
* **  dataType: 'html',*
* **  url: 'ajax.php',*
* **  type: 'post',*
* **  data : $('#form').serialize(),*
* **  beforeSend: function()  { alert('iniciando requisicao ajax'); },*
* **  error: function() { alert('ocorreu um erro'); },*
* **  success: function(data)*
*                  {*
* **  $('#mensagem').html(data)*
* **  },*
* **  complete: function() { alert('requisicao ajax completa'); }*
* **  });*
* **});*

The PHP code:
*<?php*
* **$nome = $_POST['nome'];*
* **$idade = $_POST['idade'];*
* **$timetorce = $_POST['timetorce'];*
* **echo "Nome: $nome - Idade: $idade anos - Time: $timetorce";*
*?>*
*
*
When I use the second code, the error returned by the PHP is this:
*Notice*: Undefined index: nome in *
D:\wamp\www\sites\testes\serialize\ajax.php* on line *2*
*Notice*: Undefined index: idade in *
D:\wamp\www\sites\testes\serialize\ajax.php* on line *3*
*Notice*: Undefined index: timetorce in *
D:\wamp\www\sites\testes\serialize\ajax.php* on line *4*
Nome: - Idade: anos - Time:

So, how do I use the $.ajax() method?

Thanks for help!
Pedro Vidal, Brazil.

Reply via email to