is it possible to submit this php form without refreshing the page. how would i go about setting a jquery code that can do this.
<?php
if(!isset($_POST['sthis']))
{
?>
<div id="show">
<form method="post" action="">
something<input name="sthis" type="text" id="sthis" />
<input name="s" type="submit" value="submit" id="submit" />
</form>
</div>
<?php
}
else
{
if(isset($_POST['sthis']))
$sthis = $_POST['sthis'];
if(empty($sthis)){echo 'put something in this box';}
else echo 'ready';
}
?>
You will need ajax for that:
$.ajax({ type: "POST", url: "your url here", data: "sthis=someValue", success: function(response) { alert(response); } });
Hope it helps
This is how to use jQuery:
HTML
<form id="frmSample">
...
</form>
<div id="divResult"></div>
JQuery
$(function(){
$("#frmSample").submit(function(){
//some code here
$("#divResult").load("yourPhpCode.php", {variableName: value, variableName1: value});
});
});
Check out the documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.