Reputation: 109
When i load page index.php
, and click link DELETE
, it's will be post value to demo.php
and in demo.php
after update data into table product
why not auto submit form id="myForm"
.
.
index.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function delete_pro_fn() {
$('#mySpan').hide();
$('#loading').show();
$.ajax
(
{
url: 'demo.php',
type: 'POST',
data: $('#fid1').serialize(),
cache: false,
success: function (data) {
$('#loading').hide();
$('#mySpan').show();
$('#mySpan').html(data);
}
}
)
}
</script>
<form id="fid1" method="post" action="" ENCTYPE = "multipart/form-data" style=" display: none; ">
<input type="text" name="id_delete" value="1234567890"/>
</form>
<a href="JavaScript:delete_pro_fn()">DELETE</a>
<div id="loading" style="display: none;">Loading..........................</div>
<div id="mySpan"></div>
demo.php
<?PHP
include("connect.php");
$sql = "UPDATE product SET delete = '1' WHERE id = '$_POST[id_delete]'";
$dbQuery = mysql_query($sql);
?>
<form name="myForm" id="myForm" action="products.php" method="POST">
<input name="delete" value="1" />
</form>
<script type="text/javascript">
window.onload = function(){
document.forms['myForm'].submit()
}
</script>
Upvotes: 0
Views: 5053
Reputation: 1707
To submit the form after the ajax post, just:
$('#myForm').submit();
edit complete function:
function delete_pro_fn() {
$('#mySpan').hide();
$('#loading').show();
$.ajax
(
{
url: 'demo.php',
type: 'POST',
data: $('#fid1').serialize(),
cache: false,
success: function (data) {
$('#loading').hide();
$('#mySpan').show();
$('#mySpan').html(data);
$('#myForm').submit();
}
}
)
}
</script>
Upvotes: 1