tags:

views:

41

answers:

2

i have a form that is dynamically built. so the number of form elements arr not fixed. I wnat to send whole of $_POSt data from the form using jquery to back end for processing .i cant use jquery form plugin as the jquery version i am using is old.

any other way ? i tied to do like this

$.post('all_include_files/update_save.php',{variable:"<?php echo json_encode($_POST) ?>"},function(data)
{
alert(data);
})

but did not work

A: 

Use .serialize() (was added in jQuery 1.0)

The .serialize() method creates a text string in standard URL-encoded notation. It operates on a jQuery object representing a set of form elements.

E.g.

var data = $('#formid').serialize()
Felix Kling
+1  A: 

Take a look at jQuery.serialize().

It looks like what you're trying to accomplish is similar to:

$.ajax({
  type: 'POST',
  url: 'all_include_files/update_save.php',
  data: $("form").serialize(),
  success: function(result){ alert(result); }
});
JMP
okie.. this looks fine.. whats the difference b/w $.post and $.ajax ???
pradeep
.post() is a shorthand version of .ajax() that assumes some default instructions for you.
JMP
okie so i can use either $.post or $.ajax rite
pradeep
Yes, either implementation should return the same result. I used .ajax() in my example because I felt like it was easier to illustrate my point.
JMP
but how do i unserialize it at back end ? i did not find specifi function for tht
pradeep
Serialize will use the browser's default posting technique. That is, your server side code can treat the jQuer.serialize()'ed data as if it were a traditional form post. I'm not sure what the equivalent in PHP is, but in ASP.NET, you would to a Request.Form["inputName"].
JMP
hey we use $_POST in php to get post data . but it did not work .i had to use parse_str($_POST['datas']) where datas is the serialized variable ..
pradeep