If you have a form with numerous fields and want to send those fields via ajax. Here comes the easy way, use the serialise in jQuery.
Follow the examples
var post_form:$("#daily_checklist_form").serialize(); $.ajax({ method: "POST", url: "someurl.php", data: { data:post_form } }) .done(function( msg ) { //alert( "Data Saved: " + msg ); });
And next question how do we unserialize the jQuery serialized data in PHP. The answer is you don’t need to unserialize directly as the PHP does. You just need to parse the string. I will be in this format
"param1=someVal¶m2=someOtherVal"
$params = array(); parse_str($_POST['data'], $params); print_r($params);
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply