1

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.

Jack Hales
  • 1,574
  • 23
  • 51

1 Answers1

2

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);
});
Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
  • So instead of submitting the form, just send the form data to the api instead? Saves time I guess `:)` let me try this one second – Jack Hales Nov 19 '16 at 06:42
  • @Jek an also i think you may want to look at this http://stackoverflow.com/questions/1792603/how-do-i-php-unserialize-a-jquery-serialized-form – Kanishka Panamaldeniya Nov 19 '16 at 06:44