php - ajax $_POST data then redirect to new page -
i have been going crazy last 2 weeks trying work. calling mysql db, , displaying data in table. along way creating href links delete , edit records. delete pulls alert , stays on same page. edit link post data redirect editdocument.php
here php:
<?php foreach ($query $row){ $id = $row['document_id']; echo ('<tr>'); echo ('<td>' . $row [clientname] . '</td>'); echo ('<td>' . $row [documentnum] . '</td>'); echo "<td><a href='**** need code here ****'>edit</a>"; echo " / "; echo "<a href='#' onclick='deletedocument( {$id} );'>delete</a></td>"; // calls javascript function deletedocument(id) stays on same page echo ('</tr>'); } //end foreach ?>
i tried (without success) ajax method:
<script> function editdocument(id){ var edit_id = id; $.ajax({ type: 'post', url: 'editdocument.php', data: 'edit_id='edit_id, success: function(response){ $('#result').html(response); } }); } </script>
i have been using <? print_r($_post); ?>
on editdocument.php see if id has posted.
i realize jquery/ajax need use. not sure if need use onclick
, .bind
, .submit
, etc.
here parameters code need:
- posts $id value:
$_post[id] = $id
- redirects editdocument.php (where use $_post[id]).
- does not affect other
<a>
or other tags on page. - i want ajax "virtually" create
<form>
if needed. not want put them in php code. - i not want use button.
- i not want use $_get.
i don't know missing. have been searching stackoverflow.com , other sites. have been trying sample code. think "can't see forest through trees." maybe different set of eyes. please help.
thank in advance.
update:
according dany caissy, don't need use ajax. need $_post[id] = $id; , redirect editdocument.php. use query on editdocument.php create sticky form.
ajax used when need communicate database without reloading page because of user action on site.
in case, want redirect page, after modify database using ajax, makes little sense.
what should put data in form, form's action should lead editdocument, , page handle post/get parameters , whatever database interaction need done.
in short : if ever think need redirect user after ajax call, don't need ajax.
Comments
Post a Comment