Hi,

Here " data : $('#form').serialize() " you are serializing the data,
so in the php i guess you need to unserialize it, dunno but maybe that
is the problem with your script.

Here's how i do it, i use json btw:

$.ajax({
    type: 'POST',
    url:  'ajax.php',
    data: 'quantidade=' + $('#quantidade').val() ,
    dataType : 'json',

    success: function(data){
        $('#my-div').html(data.returned_variable_from_php);
    },

    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert('Error!');
    }
});



I get the values individually, maybe its a bad way but i like this
way :)


Im a newbie at jQuery too but if you need any help you can add me on
msn, im portuguese :)

Regards
Bruno

On 18 Jul, 17:36, Pedro Vidal <pedrorvi...@gmail.com> wrote:
> 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