i need make form non reloading one, ajax/jquery. tried @ other post i'm not getting wiser. me out.
its news reaction system.
this reactions.php
<?php $result = mysql_query('select id paginas '. 'where url="'. mysql_escape_string($_server['request_uri']).'";'); if (mysql_num_rows($result)==1) { $row = mysql_fetch_array($result); $pagina_id = $row['id']; } else { mysql_query('insert paginas set url="'. $_server['request_uri'].'";'); $pagina_id = mysql_insert_id(); } ?><style type="text/css" media="screen"> @import url('../_img/style.css'); </style> <script src="../../jquery-2.1.4.js"></script> <script> $j(function () { $j('form').bind('click', function (event) { event.preventdefault();// using page stop being refreshing $j.ajax({ type: 'post', url: 'post.php', data: $j('form').serialize(), success: function () { alert('je reactie geplaatst !'); } }); }); }); </script> <?php $result = mysql_query('select * reacties '. 'where pagina="'.$pagina_id.'";'); if (mysql_num_rows($result)==0) { echo "<div class=\"box\">"; echo "<div class=\"menulitems\" style=\"margin: 5px 5px 5px 5px; padding-bottom: 5px;\">"; echo 'er zijn nog geen reacties.'; echo "</div>"; echo "</div>"; } else { while ($row = mysql_fetch_array($result)) { // deze reactie weergeven echo "<div class=\"box\">"; echo "<div class=\"titlesmall\">"; echo ''.$row['naam'].' - '.$row['email'].''; echo "</div>"; echo "<div class=\"menulitems\" style=\"margin: 5px 5px 5px 5px; padding-bottom: 5px;\">"; echo ''.$row['reactie'].''; echo "</div>"; echo "</div>"; } } ?> <div class="box"> <div class="titlesmall"><strong>reageer</strong></div> <table width="100%" cellpadding="3" cellspacing="0"> <form> <tr><td class="label"> <label for="naam">naam*</label> </td><td colspan="1" align="left"> <input class="required" type="text" name="naam" maxlength="255" /> </td><td> <tr><td class="label"> <label for="email">email</label> </td><td colspan="1" align="left"> <input type="text" name="email" maxlength="255" /> </td><td> <tr><td class="label"> <label for="reactie">reactie*</label> </td><td colspan="1" align="left"> <textarea name="reactie" cols="50" rows="5"></textarea> <br /> <input type="submit" name="submit" value="verstuur" /> <input class="button" type="reset" name="submit2" value=" reset " /> </td><td> </form> </div> this post.php
<?php if (isset($_post['naam'])) { mysql_query('insert reacties set pagina="'. $pagina_id.'", naam="'.$_post['naam']. '", email="'.$_post['email'].'", '. 'reactie="'.$_post['reactie'].'";'); } ?>
Comments
Post a Comment