Jek Jek - 20 days ago 5
PHP Question

How to send all current post data in jQuery AJAX call

So I'm working on a site and I am setting up a register system, and I want the site to take all of the current

POST
data
(after the request was made)
and send the current
POST
data in an
AJAX
call, like:

$.post('/api/post', {
"type":"register",
"pdata":POST_DATA
}, function(data){
alert(data);
});


And have the
PHP Backend
be able to take in the
$_POST['pdata']
and use that as the data it's going to use, just to make the transfer safer and easier.

Answer

Try use serialize()

You can send all your form data

$.post('/api/post', {
  "type":"register",
  "pdata":$('.your_form_class_name').serialize()
}, function(data){
  alert(data);
});