ajax - Automate AJAXed forms with Jquery -
i want improve website , figured out way submitting forms via ajax. but, have many forms inpractical $('#formx').submit(). wondering if there way automatically making universal markup like;
<form class="ajax_form" meta-submit="ajax/pagename.php"> <input type="text" name="inputx" value="x_value"> <input type="text" name="inputy" value="y_value"> </form>
and have submit ajax/pagename.php, automatically includes inputx , inputy? not save me lot of time lot of lines of code written.
first question hope it's not stupid 1 :)
something should work forms. it uses jquery - available in project? specific code chunk hasn't been tested per say, use method time. is wonderful time saver. notice changed meta-submit
data-submit
value can fetched using $('.elemenet_class').data('submit');
html
<!-- note: form items must have unique 'name' attribute --> <form action="javascript:void(0);" class="ajax_form" data-submit="ajax/pagename.php"> <input type="text" name="inputx" value="x_value"> <input type="text" name="inputy" value="y_value"> <input type="submit" value="go" /> </form>
javascript
$('.ajax_form').submit(function(e){ var path = $(this).attr('data-submit'); //path action var data = $(this).serialize(); //form data $.post(path, {data:data}, function(obj){ }); return false; })
php
//debugging code //var_dump($_post); //die(null); $data = $_post['data']; $inputx = $data['inputx']; $inputy = $data['inputy'];
Comments
Post a Comment